package com.xinchuang.service.targetSystem.Impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xinchuang.common.*;
import com.xinchuang.entity.targetSystem.target.KnowHeard;
import com.xinchuang.entity.targetSystem.target.KnowRelationData;
import com.xinchuang.entity.targetSystem.target.TargetData;
import com.xinchuang.mapper.targetSystem.*;
import com.xinchuang.mapper.targetSystem.weapon.WeaponHouseMapper;
import com.xinchuang.entity.targetSystem.ValueData;
import com.xinchuang.entity.targetSystem.Zone;
import com.xinchuang.entity.targetSystem.external.Blow;
import com.xinchuang.entity.targetSystem.system.SystemMaster;
import com.xinchuang.entity.targetSystem.system.SystemPosition;
import com.xinchuang.entity.targetSystem.system.SystemsMaster;
import com.xinchuang.entity.targetSystem.system.TargetType;
import com.xinchuang.entity.targetSystem.target.*;
import com.xinchuang.entity.targetSystem.weapon.WeaponRelation;
import com.xinchuang.service.targetSystem.KnowService;
import com.xinchuang.service.targetSystem.SystemElseService;
import com.xinchuang.sqlite.TargetRepo;
import com.xinchuang.util.FileElseUtil;
import com.xinchuang.util.SnowflakeIdWorker;
import com.xinchuang.utils.MyUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.*;

/**
 * @ClassName KnowServiceImpl
 * @Description: TODO(知识维护)
 * @Author zhangxuan
 * @Date 2022-02-22 16:28
 * @Verion V1.0
 */
@Slf4j
@Service
public class KnowServiceImpl implements KnowService {

    @Resource
    private TargetMapper targetMapper;

    @Resource
    private KnowMapper knowMapper;

    @Resource
    private TargetTypeMapper targetTypeMapper;

    @Resource
    private SystemMasterMapper systemMasterMapper;

    @Resource
    private SystemRelationMapper systemRelationMapper;

    @Resource
    private SystemsMasterMapper systemsMasterMapper;

    @Resource
    private SystemsRelationMapper systemsRelationMapper;

    @Resource
    private SystemPositionMapper systemPositionMapper;

    @Resource
    private ZoneMapper zoneMapper;

    @Resource
    private KeyWordSystem keyWordSystem;

    @Resource
    private Element element;

    @Resource
    private SystemTypeMapper systemTypeMapper;

    @Resource
    private WeaponHouseMapper weaponHouseMapper;

    @Resource
    private SystemElseService systemElseService;

    private TargetRepo repo = new TargetRepo();

    private SnowflakeIdWorker snow = new SnowflakeIdWorker(1, 1);

    /**
     * 保留后面位数
     */
    private int SUFF = 6;

    private KnowData getKnowData(String id, int sign) {
        KnowData knowData = null;
        switch (sign) {
            case 0:
                knowData = knowMapper.selectKnowTargetOnly(id);
                break;
            case 1:
                knowData = knowMapper.selectKnowSystemOnly(id);
                break;
            case 2:
                knowData = knowMapper.selectKnowSystemsOnly(id);
                break;
        }
        return knowData;
    }

    @Override
    public Result addKnow(KnowData knowData, int sign, String userId) {
        if (StringUtils.isBlank(knowData.getId()) || knowData.getId().equals("0")) {
            knowData.setId(snow.nextId() + "");
        } else {
            KnowData old = getKnowData(knowData.getId(), sign);
            if (null != old && old.getIndexData().equals(knowData.getIndexData())) {
                knowMapper.deleteRelationByRelId(old.getId());
            } else if (null == old) {
                return ResultUtil.error(ResultEnum.KNOW_TYPE_IS_NOT_EMPTY);
            }
        }
        synchronized (this) {
            String id = null;
            switch (sign) {
                case 0:
                    id = knowMapper.selectTargetKnowId(knowData.getId());
                    if (StringUtils.isNotBlank(id)) {
                        knowMapper.updateTargetKnow(knowData);
                    } else {
                        knowMapper.addTargetKnow(knowData);
                    }
                    break;
                case 1:
                    id = knowMapper.selectSystemKnowId(knowData.getId());
                    if (StringUtils.isNotBlank(id)) {
                        knowMapper.updateSystemKnow(knowData);
                    } else {
                        knowMapper.addSystemKnow(knowData);
                    }
                    break;
                case 2:
                    id = knowMapper.selectSystemsKnowId(knowData.getId());
                    if (StringUtils.isNotBlank(id)) {
                        knowMapper.updateSystemsKnow(knowData);
                    } else {
                        knowMapper.addSystemsKnow(knowData);
                    }
                    break;
            }
        }
        return ResultUtil.success(knowData.getId());
    }

    @Override
    public Result deleteKnow(String id, int sign) {
        switch (sign) {
            case 0:
                knowMapper.deleteTargetKnow(id);
                deleteKnowValue(id);
                break;
            case 1:
                knowMapper.deleteSystemKnow(id);
                break;
            case 2:
                knowMapper.deleteSystemsKnow(id);
                break;
        }
        return ResultUtil.success();
    }

    @Override
    public Result selectKnowList(int pageNum, int pageSize, String relId, int sign, String type) {
        PageHelper.startPage(pageNum, pageSize, "create_time DESC");
        List<KnowData> list = null;
        switch (sign) {
            case 0:
                list = knowMapper.selectTargetKnowList(relId, null);
                break;
            case 1:
                list = knowMapper.selectSystemKnowList(relId, null);
                break;
            case 2:
                list = knowMapper.selectSystemsKnowList(relId, null);
                break;
        }
        PageInfo<KnowData> pageInfo = new PageInfo<>(list);
        Map<String, Object> resultMap = new HashMap<>();
        List<Map<String, Object>> resultList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(pageInfo.getList())) {
            for (int i = 0; i < list.size(); i++) {
                KnowData knowData = list.get(i);
                HashMap<String, Object> map = new HashMap<>();
                map.put("number", ((pageNum - 1) * pageSize) + i + 1);
                map.put("id", knowData.getId());
                map.put("kind", knowData.getKind());
                map.put("name", knowData.getName());
                map.put("type", knowData.getType());
                List dataList = FileElseUtil.getStringTransitionList(knowData.getIndexData());
                map.put("index", dataList);
                map.put("describe", knowData.getRemark());
                map.put("weapon", knowData.getWeapon());
                if (sign == 0 || sign == 1) {
                    List<Map<String, String>> indexList = new ArrayList<>();
                    if (StringUtils.isNotBlank(knowData.getType())) {
                        List<Map<String, String>> indexPutc = new ArrayList<>();
                        if (knowData.getType().equals("1")) {
                            if (sign == 1) {
                                indexPutc = knowMapper.selectTargetIndexPutc(1);
                            } else {
                                indexPutc = knowMapper.selectTargetIndexPutc(type.equals("1") ? 1 : 2);
                            }
                        } else {
                            if (sign == 1) {
                                indexPutc = knowMapper.selectTargetIndexPuts(type);
                            } else {
                                indexPutc = knowMapper.selectTargetIndexPuts(relId);
                            }
                        }
                        if (CollectionUtil.isNotEmpty(indexPutc)) {
                            indexList.addAll(indexPutc);
                        }
                    }
                    map.put("indexList", indexList);
                }
                resultList.add(map);
            }
        }
        resultMap.put("KnowList", resultList);
        resultMap.put("pageNum", pageInfo.getPageNum());
        resultMap.put("pageSize", pageInfo.getPageSize());
        resultMap.put("total", pageInfo.getTotal());
        resultMap.put("pageAll", pageInfo.getPages());
        return ResultUtil.success(resultMap);
    }

    @Override
    public Result selectKnowRelationList(String relId, int sign) {
        KnowData knowData = getKnowData(relId, sign);
        if (null != knowData) {
            Map<String, Object> resultMap = new HashMap<>();
            String heard = knowMapper.getHeard(knowData.getId());
            if (StringUtils.isNotBlank(heard)) {
                resultMap.put("detColumns", heard);
            } else {
                resultMap.put("detColumns", new ArrayList<>());
            }
            List<KnowRelationData> list = knowMapper.selectKnowRelationList(knowData.getId());
            if (CollectionUtil.isNotEmpty(list)) {
                List<Map<String, Object>> resultList = new ArrayList<>();
                List data = FileElseUtil.getStringTransitionList(knowData.getIndexData());
                for (KnowRelationData knowRelationData : list) {
                    Map<String, Object> map = new LinkedHashMap<>();
                    map.put("result", knowRelationData.getEffect());
                    for (int i = 0; i < data.size(); i++) {
                        switch (i) {
                            case 0:
                                map.put(data.get(i).toString(), knowRelationData.getIndexOne());
                                break;
                            case 1:
                                map.put(data.get(i).toString(), knowRelationData.getIndexTwo());
                                break;
                            case 2:
                                map.put(data.get(i).toString(), knowRelationData.getIndexThree());
                                break;
                        }
                    }
                    map.put("knowId", knowRelationData.getId());
                    resultList.add(map);
                }

                resultMap.put("dataList", resultList);
            } else {
                resultMap.put("dataList", new ArrayList<>());
            }
            return ResultUtil.success(resultMap);
        } else {
            return ResultUtil.error(ResultEnum.KNOW_TYPE_IS_NOT_EMPTY);
        }
    }

    @Override
    public Result deleteKnowRelation(String knowId, String id, int sign) {
        knowMapper.deleteRelation(knowId);
        if (sign == 0 || sign == 1) {
            return selectKnowRelationList(id, sign);
        } else {
            return ResultUtil.success("删除成功", null);
        }
    }

    @Override
    public Result addKnowRelation(String relId, int sign, JSONArray array, String heard) {
        KnowData knowData = getKnowData(relId, sign);
        if (null != knowData) {
            knowMapper.deleteRelationByRelId(relId);
            if (CollectionUtil.isNotEmpty(array)) {
                KnowHeard knowHeard = new KnowHeard();
                knowHeard.setId(relId);
                knowHeard.setRemark(heard);
                knowMapper.addKnowHeard(knowHeard);
                List data = FileElseUtil.getStringTransitionList(knowData.getIndexData());
                List<KnowRelationData> list = new ArrayList<>();
                for (int i = array.size() - 1; i >= 0; i--) {
                    KnowRelationData relationData = new KnowRelationData();
                    JSONObject jsonObject = array.getJSONObject(i);
                    if (StringUtils.isNotBlank(jsonObject.getString("result")) && jsonObject.size() != 1) {
                        for (int j = 0; j < data.size(); j++) {
                            switch (j) {
                                case 0:
                                    relationData.setIndexOne(null != jsonObject.get(data.get(j)) ? jsonObject.get(data.get(j)).toString() : "");
                                    break;
                                case 1:
                                    relationData.setIndexTwo(null != jsonObject.get(data.get(j)) ? jsonObject.get(data.get(j)).toString() : "");
                                    break;
                                case 2:
                                    relationData.setIndexThree(null != jsonObject.get(data.get(j)) ? jsonObject.get(data.get(j)).toString() : "");
                                    break;
                            }
                        }
                    }
                    relationData.setId(snow.nextId() + "");
                    relationData.setRelId(relId);
                    relationData.setEffect(jsonObject.getString("result"));
                    list.add(relationData);
                }
                knowMapper.addKnowRelations(list);
            }
            return ResultUtil.success();
        } else {
            return ResultUtil.error(ResultEnum.KNOW_TYPE_IS_NOT_EMPTY);
        }
    }

    @Override
    public Result selectPut(int sign, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> list = null;
        switch (sign) {
            case 1:
                list = knowMapper.selectSystemPut(null, null, null, null);
                break;
            case 2:
                list = knowMapper.selectSystemsPut(null, null, null, null);
                break;
        }
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
        Map<String, Object> resultMap = new HashMap<>();
        List<Map<String, Object>> resultList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(pageInfo.getList())) {
            for (Map<String, Object> map : pageInfo.getList()) {
                Map<String, Object> main = new HashMap<>();
                if (sign == 1) {
                    main.put("sId", map.get("value"));
                    main.put("systemName", map.get("label"));
                } else {
                    main.put("sysId", map.get("value"));
                    main.put("systemsName", map.get("label"));
                }
                resultList.add(main);
            }
        }
        resultMap.put("KnowList", resultList);
        resultMap.put("pageNum", pageInfo.getPageNum());
        resultMap.put("pageSize", pageInfo.getPageSize());
        resultMap.put("total", pageInfo.getTotal());
        resultMap.put("pageAll", pageInfo.getPages());
        return ResultUtil.success(resultMap);
    }

    @Override
    public Result selectTree(int sign, String keyword, String country, String classify) {
        List<String> countryList = null;
        if (CollectionUtil.isNotEmpty(JSONArray.parseArray(country))) {
            countryList = JSONArray.parseArray(country, String.class);
            if (StringUtils.isNumeric(countryList.get(0))) {
                ArrayList<String> strings = new ArrayList<>();
                for (String s : countryList) {
                    Zone zone = zoneMapper.getZoneByAdcode(s);
                    if (zone.getLevel().equals("city")) {
                        List<Zone> parent = zoneMapper.getZoneByParent(zone.getAdcode());
                        if (CollectionUtil.isNotEmpty(parent)) {
                            for (Zone zone1 : parent) {
                                strings.add("[\"" + zone1.getParent() + "\",\"" + zone1.getAdcode() + "\"]");
                            }
                        }
                    } else {
                        if (ObjectUtil.isNotEmpty(zone)) {
                            strings.add("[\"" + zone.getParent() + "\",\"" + zone.getAdcode() + "\"]");
                        }
                    }
                }
                countryList = strings;
            }
        }
        List<String> classifyList = null;
        if (CollectionUtil.isNotEmpty(JSONArray.parseArray(classify))) {
            if (sign == 1) {
                classifyList = knowMapper.selectSystemTypeId(JSONArray.parseArray(classify, String.class));
            } else {
                classifyList = knowMapper.selectSystemsTypeId(JSONArray.parseArray(classify, String.class));
            }
            if (CollectionUtil.isEmpty(classifyList)) {
                classifyList = null;
            }
        }
        List<Map<String, Object>> list = null;
        if (sign == 4) {
            return ResultUtil.success(getTargetAndSubAll());
        }
        switch (sign) {
            case 1:
                list = knowMapper.selectSystemPut(null, StringUtils.isNotBlank(keyword) ? keyword : null, countryList, classifyList);
                break;
            case 2:
            case 3:
                list = knowMapper.selectSystemsPut(null, StringUtils.isNotBlank(keyword) ? keyword : null, countryList, classifyList);
                break;
        }
        List<Map<String, Object>> resultList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(list)) {
            for (Map<String, Object> map : list) {
                Map<String, Object> main = new HashMap<>();
                if (sign == 1) {
                    main.put("sId", map.get("value"));
                    main.put("systemName", map.get("label"));
                    main.put("system", true);
                    SystemPosition position = systemPositionMapper.getPositionById(map.get("value").toString());
                    if (null != position) {
                        main.put("position", FileElseUtil.getStringTransitionList(position.getPositions()));
                        main.put("height", StringUtils.isNotBlank(position.getHeight()) ? position.getHeight() : null);
                        main.put("viewDistances", FileElseUtil.getStringTransitionList(position.getViewDistances()));
                    } else {
                        main.put("position", new ArrayList<>());
                        main.put("height", null);
                        main.put("viewDistances", new ArrayList<>());
                    }
                    //查询包含的目标
                    List<Map<String, Object>> maps = systemRelationMapper.selectSystemRelationTargetIdAndName(null != map.get("value") ? map.get("value").toString() : "");
                    if (CollectionUtil.isNotEmpty(maps)) {
                        for (Map<String, Object> m : maps) {
                            SystemPosition tPosition = systemPositionMapper.getPositionById(m.get("targetId").toString());
                            if (null != tPosition) {
                                m.put("height", StringUtils.isNotBlank(tPosition.getHeight()) ? tPosition.getHeight() : null);
                                m.put("viewDistances", FileElseUtil.getStringTransitionList(tPosition.getViewDistances()));
                            } else {
                                m.put("height", null);
                                m.put("viewDistances", new ArrayList<>());
                            }
                            if (null != m.get("lon")) {
                                m.put("position", Arrays.asList(m.get("lon"), m.get("lat"), null != m.get("height") ? m.get("height") : 0));
                            } else {
                                m.put("position", new ArrayList<>());
                            }
                            m.put("radius", FileElseUtil.getStringTransitionDouble(zoneMapper.getTypeElse(m.get("targetId").toString())));
                            if (null != m.get("targetClassify")) {
                                String targetClassify = targetTypeMapper.getTypeName(m.get("targetClassify").toString());
                                m.put("targetType", StringUtils.isNotBlank(targetClassify) ? targetClassify : "");
                                String icon = targetTypeMapper.getSign(MyUtil.classToString(m.get("targetClassify").toString()));
                                m.put("icon", StringUtils.isNotBlank(icon) ? this.keyWordSystem.getSERVER_URL() + "/sign/" + icon : null);
                            } else {
                                m.put("targetType", "");
                                m.put("icon", null);
                            }
                            m.put("system", false);
                        }
                        main.put("children", maps);
                    } else {
                        main.put("children", new ArrayList<>());
                    }
                } else {
                    main = systemElseService.selectSystemTree(map.get("value").toString(), map.get("label").toString());
//                    main.put("sysId", map.get("value"));
//                    main.put("systemsName", map.get("label"));
//                    main.put("systems", true);
//                    SystemPosition position = systemPositionMapper.getPositionById(map.get("value").toString());
//                    if (null != position) {
//                        main.put("position", FileElseUtil.getStringTransitionList(position.getPositions()));
//                        main.put("height", StringUtils.isNotBlank(position.getHeight()) ? position.getHeight() : null);
//                        main.put("viewDistances", FileElseUtil.getStringTransitionList(position.getViewDistances()));
//                    } else {
//                        main.put("position", new ArrayList<>());
//                        main.put("height", null);
//                        main.put("viewDistances", new ArrayList<>());
//                    }
//                    if (null != map.get("value")) {
                        //查询单个体系
//                        SystemsMaster systemsMaster = systemsMasterMapper.selectSystemsOnly(map.get("value").toString());
//                        List<Map<String, Object>> systemLists = new ArrayList<>();
//                        List<Map<String, Object>> systemList = new ArrayList<>();
//                        if (StringUtils.isNotBlank(systemsMaster.getIncludeType())) {
//                            String[] split = systemsMaster.getIncludeType().split(",");
//                            List<String> asList = Arrays.asList(split);
//                            if (CollectionUtil.isNotEmpty(asList)) {
//                                //查询包含系统
//                                List<Map<String, String>> maps = systemsMasterMapper.selectSystemIdAndName(asList);
//                                if (CollectionUtil.isNotEmpty(maps)) {
//                                    if (sign == 3) {
//                                        for (Map<String, String> stringStringMap : maps) {
//                                            if (null != stringStringMap) {
//                                                Map<String, Object> systemMap = new HashMap<>();
//                                                systemMap.put("sId", stringStringMap.get("sId"));
//                                                systemMap.put("systemName", stringStringMap.get("systemName"));
//                                                systemMap.put("systems", false);
//                                                SystemPosition systemPosition = systemPositionMapper.getPositionById(stringStringMap.get("sId"));
//                                                if (null != systemPosition) {
//                                                    systemMap.put("position", FileElseUtil.getStringTransitionList(systemPosition.getPositions()));
//                                                    systemMap.put("height", StringUtils.isNotBlank(systemPosition.getHeight()) ? systemPosition.getHeight() : null);
//                                                    systemMap.put("viewDistances", FileElseUtil.getStringTransitionList(systemPosition.getViewDistances()));
//                                                } else {
//                                                    systemMap.put("position", new ArrayList<>());
//                                                    systemMap.put("height", null);
//                                                    systemMap.put("viewDistances", new ArrayList<>());
//                                                }
//                                                List<Map<String, Object>> targetList = new ArrayList<>();
//                                                //查询系统包含目标
//                                                List<Map<String, Object>> targetIdAndName = systemRelationMapper.selectSystemRelationTargetIdAndName(stringStringMap.get("sId"));
//                                                if (CollectionUtil.isNotEmpty(targetIdAndName)) {
//                                                    for (Map<String, Object> stringObjectMap : targetIdAndName) {
//                                                        if (null != stringObjectMap) {
//                                                            Map<String, Object> targetMap = new HashMap<>();
//                                                            targetMap.put("targetId", stringObjectMap.get("targetId"));
//                                                            targetMap.put("targetName", stringObjectMap.get("targetName"));
//                                                            targetMap.put("children", new ArrayList<>());
//                                                            targetMap.put("system", false);
//                                                            SystemPosition targetPosition = systemPositionMapper.getPositionById(stringObjectMap.get("targetId").toString());
//                                                            if (null != targetPosition) {
//                                                                targetMap.put("height", StringUtils.isNotBlank(targetPosition.getHeight()) ? targetPosition.getHeight() : null);
//                                                                targetMap.put("viewDistances", FileElseUtil.getStringTransitionList(targetPosition.getViewDistances()));
//                                                            } else {
//                                                                targetMap.put("height", null);
//                                                                targetMap.put("viewDistances", new ArrayList<>());
//                                                            }
//                                                            if (null != stringObjectMap.get("lon")) {
//                                                                targetMap.put("position", Arrays.asList(stringObjectMap.get("lon"), stringObjectMap.get("lat"), stringObjectMap.get("height")));
//                                                            } else {
//                                                                targetMap.put("position", new ArrayList<>());
//                                                            }
//                                                            targetMap.put("radius", FileElseUtil.getStringTransitionDouble(zoneMapper.getTypeElse(stringObjectMap.get("targetId").toString())));
//                                                            if (null != stringObjectMap.get("targetClassify")) {
//                                                                String icon = targetTypeMapper.getSign(MyUtil.classToString(stringObjectMap.get("targetClassify").toString()));
//                                                                targetMap.put("icon", StringUtils.isNotBlank(icon) ? this.keyWordSystem.getSERVER_URL() + "/sign/" + icon : null);
//                                                            } else {
//                                                                targetMap.put("icon", null);
//                                                            }
//                                                            targetList.add(targetMap);
//                                                        }
//                                                    }
//                                                }
//                                                systemMap.put("children", targetList);
//                                                systemList.add(systemMap);
//                                            }
//                                        }
//                                    } else {
//                                        Map<String, Object> systemMap = null;
//                                        for (Map<String, String> stringStringMap : maps) {
//                                            if (null != stringStringMap) {
//                                                systemMap = new HashMap<>();
//                                                systemMap.put("sId", stringStringMap.get("sId"));
//                                                systemMap.put("systemName", stringStringMap.get("systemName"));
//                                                systemMap.put("systems", false);
//                                                SystemPosition systemPosition = systemPositionMapper.getPositionById(stringStringMap.get("sId"));
//                                                if (null != systemPosition) {
//                                                    systemMap.put("position", FileElseUtil.getStringTransitionList(systemPosition.getPositions()));
//                                                    systemMap.put("height", StringUtils.isNotBlank(systemPosition.getHeight()) ? systemPosition.getHeight() : null);
//                                                    systemMap.put("viewDistances", FileElseUtil.getStringTransitionList(systemPosition.getViewDistances()));
//                                                } else {
//                                                    systemMap.put("position", new ArrayList<>());
//                                                    systemMap.put("height", null);
//                                                    systemMap.put("viewDistances", new ArrayList<>());
//                                                }
//                                                systemLists.add(systemMap);
//                                            }
//                                        }
//                                    }
//                                }
//                            }
//                        }
//                        //系统之外目标
//                        List<Map<String, Object>> mapList = systemsRelationMapper.selectNoSystemTargetList(map.get("value").toString());
//                        if (CollectionUtil.isNotEmpty(mapList)) {
//                            if (sign == 3) {
//                                Map<String, Object> systemMap = new HashMap<>();
//                                systemMap.put("sId", "002");
//                                systemMap.put("systemName", "其他");
//                                systemMap.put("systems", false);
//                                systemMap.put("position", new ArrayList<>());
//                                systemMap.put("height", null);
//                                systemMap.put("viewDistances", new ArrayList<>());
//                                List<Map<String, Object>> targetList = new ArrayList<>();
//                                for (Map<String, Object> stringObjectMap : mapList) {
//                                    if (null != stringObjectMap) {
//                                        Map<String, Object> targetMap = new HashMap<>();
//                                        targetMap.put("targetId", stringObjectMap.get("targetId"));
//                                        targetMap.put("targetName", stringObjectMap.get("targetName"));
//                                        targetMap.put("children", new ArrayList<>());
//                                        targetMap.put("system", false);
//                                        SystemPosition targetPosition = systemPositionMapper.getPositionById(stringObjectMap.get("targetId").toString());
//                                        if (null != targetPosition) {
//                                            targetMap.put("height", StringUtils.isNotBlank(targetPosition.getHeight()) ? targetPosition.getHeight() : null);
//                                            targetMap.put("viewDistances", FileElseUtil.getStringTransitionList(targetPosition.getViewDistances()));
//                                        } else {
//                                            targetMap.put("height", null);
//                                            targetMap.put("viewDistances", new ArrayList<>());
//                                        }
//                                        if (null != stringObjectMap.get("lon")) {
//                                            targetMap.put("position", Arrays.asList(stringObjectMap.get("lon"), stringObjectMap.get("lat"), stringObjectMap.get("height")));
//                                        } else {
//                                            targetMap.put("position", new ArrayList<>());
//                                        }
//                                        targetMap.put("radius", FileElseUtil.getStringTransitionDouble(zoneMapper.getTypeElse(stringObjectMap.get("targetId").toString())));
//                                        if (null != stringObjectMap.get("targetClassify")) {
//                                            String icon = targetTypeMapper.getSign(MyUtil.classToString(stringObjectMap.get("targetClassify").toString()));
//                                            targetMap.put("icon", StringUtils.isNotBlank(icon) ? this.keyWordSystem.getSERVER_URL() + "/sign/" + icon : null);
//                                        } else {
//                                            targetMap.put("icon", null);
//                                        }
//                                        targetList.add(targetMap);
//                                    }
//                                }
//                                systemMap.put("children", targetList);
//                                systemList.add(systemMap);
//                            }
//                        }
//                        if (CollectionUtil.isNotEmpty(systemList) || CollectionUtil.isNotEmpty(systemLists)) {
//                            main.put("children", CollectionUtil.isNotEmpty(systemList) ? systemList : CollectionUtil.isNotEmpty(systemLists) ? systemLists : new ArrayList<>());
//                        } else {
//                            main.put("children", new ArrayList<>());
//                        }
//                    } else {
//                        main.put("children", new ArrayList<>());
//                    }
                }
                resultList.add(main);
            }
        }
        return ResultUtil.success(resultList);
    }

    @Override
    public Result selectIndexPut(int type, Integer target, Integer sign, String relId) {
        List<Map<String, String>> resultList = null;
        if (type == 1) {
            resultList = knowMapper.selectTargetIndexPutc(target);
        } else {
            resultList = knowMapper.selectTargetIndexPuts(relId);
        }
        return ResultUtil.success(resultList != null ? resultList : new ArrayList<>());
    }

    /**
     * @return com.zkwc.targetmanage.common.Result
     * @author zhangxuan
     * @Description TODO 查询目标分析
     * @Date 14:57 2022/2/25
     * @Param [targetId, type]
     **/
    @Override
    public Result selectTargetAnalyze(String targetId, String subId, int type) {
//        Map<String, Object> resultMap = new HashMap<>();
        TargetData only = targetMapper.findTargetOnly(targetId);
        if (null == only) {
            return ResultUtil.success(only);
        }
        if (StringUtils.isBlank(subId)) {
            return targetAnalyze(only, type);
        } else {
            return subAnalyze(this.keyWordSystem.getFILE_URL() + only.getSqliteUrl(), subId, type);
        }
//        if (null == only || only.getDeleteSign() == 0) {
//            resultMap.put("targetinfo", new HashMap<>());
//            resultMap.put("subinfolist", new ArrayList<>());
//            return ResultUtil.success(resultMap);
//        }
//        //主目标分析
//        Map<String, Object> mainMap = mainTargetAnalyze(only, type, true);
//        List<Map<String, Object>> subList = subAnalyze(this.keyWordSystem.getFILE_URL() + only.getSqliteUrl(), type, true);
//        resultMap.put("targetinfo", mainMap);
//        resultMap.put("subinfolist", subList);
//        return ResultUtil.success(resultMap);
    }

    /**
     * @return com.zkwc.targetmanage.common.Result
     * @author zhangxuan
     * @Description TODO 查询要害分析
     * @Date 14:57 2022/2/25
     * @Param [targetId]
     **/
    @Override
    public Result selectCrucialAnalyze(String targetId) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("data", new ArrayList<>());
        try {
            TargetData only = targetMapper.findTargetOnly(targetId);
            if (null == only || only.getDeleteSign() == 0) {
                return ResultUtil.success(resultMap);
            }
            List<Map<String, Object>> dataList = new ArrayList<>();
            List<TargetType> type = targetTypeMapper.findTargetTypeByParantId(only.getTargetClassify());
            if (CollectionUtil.isNotEmpty(type)) {
                List<String> subData = new ArrayList<>();
                subData.add("targetName");
                subData.add("targetClassify");
                List<Map<String, Object>> subList = repo.selectTargetSubData(this.keyWordSystem.getFILE_URL() + only.getSqliteUrl(), subData);
                if (CollectionUtil.isNotEmpty(subList)) {
                    Map<String, Object> map = null;
                    for (TargetType targetType : type) {
                        map = new HashMap<>();
                        map.put("name", targetType.getTypeName());
                        List<Map<String, Object>> subDataList = new ArrayList<>();
                        for (Map<String, Object> sub : subList) {
                            if (null != sub.get("targetClassify") && sub.get("targetClassify").toString().equals(targetType.getTypeId())) {
                                Map<String, Object> m = new HashMap<>();
                                m.put("name", sub.get("targetName"));
                                Double value = knowMapper.selectTargetSubValue("003", "003", targetId, sub.get("subId").toString());
                                m.put("value", ObjectUtil.isNotNull(value) ? value : 0);
                                subDataList.add(m);
                            }
                        }
                        if (CollectionUtil.isNotEmpty(subDataList)) {
                            map.put("data", subDataList);
                            dataList.add(map);
                        }
                    }
                }
            }
            //武器库分析
            List<WeaponRelation> targetTypeId = weaponHouseMapper.selectTargetTypeId(targetId);
            List<WeaponRelation> weaponRelationList = weaponHouseMapper.selectTargetWeaponId(targetId);
            if (CollectionUtil.isNotEmpty(targetTypeId) && CollectionUtil.isNotEmpty(weaponRelationList)) {
                Map<String, Object> map = null;
                List<Map<String, Object>> subDataList = null;
                for (WeaponRelation s : targetTypeId) {
                    map = new HashMap<>();
                    map.put("name", s.getWeaponId());
                    subDataList = new ArrayList<>();
                    for (WeaponRelation weaponRelation : weaponRelationList) {
                        if (weaponRelation.getTypeId().equals(s.getTypeId())) {
                            Map<String, Object> m = new HashMap<>();
                            m.put("name", weaponRelation.getWeaponId());
                            Double value = knowMapper.selectTargetSubValue("003", "003", targetId, weaponRelation.getId());
                            m.put("value", ObjectUtil.isNotNull(value) ? value : 0);
                            subDataList.add(m);
                        }
                    }
                    if (CollectionUtil.isNotEmpty(subDataList)) {
                        map.put("data", subDataList);
                        dataList.add(map);
                    }
                }
            }
            if (CollectionUtil.isNotEmpty(dataList)) {
                resultMap.put("data", dataList);
            }
            Map<String, Object> map = selectBlowAnalyze(targetId);
            resultMap.putAll(map);
        } catch (Exception e) {
            log.error("要害分析异常", e);
        }
        return ResultUtil.success(resultMap);
    }

    /**
     * 查询目标要害ID
     *
     * @param targetId
     * @return
     */
//    public String selectCrucialTargetId(String targetId) {
//        String id = "";
//        try {
//            TargetData only = targetMapper.findTargetOnly(targetId);
//            if (null == only || only.getDeleteSign() == 0) {
//                return id;
//            }
//            List<TargetType> type = targetTypeMapper.findTargetTypeByParantId(only.getTargetClassify());
//            if (CollectionUtil.isNotEmpty(type)) {
//                int shnlz = 0;
//                List<String> subData = new ArrayList<>();
//                subData.add("crucial");
//                List<Map<String, Object>> subList = repo.selectTargetSubData(this.keyWordSystem.getFILE_URL() + only.getSqliteUrl(), subData);
//                for (Map<String, Object> sub : subList) {
//                    if (null != sub.get("crucial")) {
//                        double shnlz1 = FileElseUtil.getStringTransitionDouble(sub.get("crucial").toString());
//                        if (shnlz == 0) {
//                            shnlz = (int) shnlz1;
//                            id = sub.get("subId").toString();
//                        } else if (shnlz1 > shnlz) {
//                            shnlz = (int) shnlz1;
//                            id = sub.get("subId").toString();
//                        }
//                    }
//
//                }
//            }
//        } catch (Exception e) {
//            log.error("要害分析异常", e);
//        }
//        return id;
//    }

    /**
     * @return com.zkwc.targetmanage.common.Result
     * @author zhangxuan
     * @Description TODO 打击维护
     * @Date 16:08 2022/2/25
     * @Param [targetId]
     **/
    @Override
    public Map<String, Object> selectBlowAnalyze(String targetId) {
        Map<String, Object> resultMap = new HashMap<>();
        Map<String, Object> crucialMap = new HashMap<>();
        resultMap.put("datainfo", new HashMap<>());
        resultMap.put("targetinfolist", crucialMap);
        try {
            TargetData only = targetMapper.findTargetOnly(targetId);
            if (null == only || only.getDeleteSign() == 0) {
                return resultMap;
            }
            List<TargetType> type = targetTypeMapper.findTargetTypeByParantId(only.getTargetClassify());
            if (CollectionUtil.isNotEmpty(type)) {
                String subId = "";
                String targetClassify = "";
                String subtargetname = "";
                String weaptool = "";
                double djhmbnlz = 0D;
                double total = 0D;
                List<String> subData = new ArrayList<>();
                subData.add("targetName");
                subData.add("targetClassify");
                List<Map<String, Object>> subList = repo.selectTargetSubData(this.keyWordSystem.getFILE_URL() + only.getSqliteUrl(), subData);
                List<ValueData> valueData = knowMapper.selectTargetValue("003", "003", targetId);
                //获取要害子目标
                if (CollectionUtil.isNotEmpty(subList) && CollectionUtil.isNotEmpty(valueData)) {
                    for (ValueData valueDatum : valueData) {
                        double shnlz1 = valueDatum.getScore();
                        total += shnlz1;
                        if (djhmbnlz == 0) {
                            subId = valueDatum.getSubId();
                            djhmbnlz = shnlz1;
                        } else if (shnlz1 > djhmbnlz) {
                            subId = valueDatum.getSubId();
                            djhmbnlz = (int) shnlz1;
                        }
                    }
                }
                if (CollectionUtil.isNotEmpty(subList)) {
                    for (Map<String, Object> sub : subList) {
                        if (sub.get("subId").toString().equals(subId) && ObjectUtil.isNotEmpty(sub.get("targetClassify"))) {
                            JSONArray array = JSONArray.parseArray(sub.get("targetClassify").toString());
                            targetClassify = array.getString(array.size() - 1);
                            subtargetname = sub.get("targetName").toString();
                            break;
                        }
                    }
                }
                //匹配武器库子目标
                if (StringUtils.isBlank(targetClassify) && StringUtils.isBlank(subtargetname)) {
                    List<WeaponRelation> weaponRelations = weaponHouseMapper.selectTargetWeaponId(targetId);
                    if (CollectionUtil.isNotEmpty(weaponRelations)) {
                        for (WeaponRelation weaponRelation : weaponRelations) {
                            if (weaponRelation.getId().equals(subId)) {
                                targetClassify = "";
                                subtargetname = weaponRelation.getWeaponId();
                                weaptool = "武器库数据暂不支持武器选择";
                                break;
                            }
                        }
                    }
                }
                //打击前子目标
//                List<Map<String, Object>> dataList = new ArrayList<>();
//                if (CollectionUtil.isNotEmpty(subList)) {
//                    for (TargetType targetType : type) {
//                        Map<String, Object> map = new HashMap<>();
//                        map.put("name", targetType.getTypeName());
//                        List<Map<String, Object>> subDataList = new ArrayList<>();
//                        for (Map<String, Object> sub : subList) {
//                            if (sub.get("subId").toString().equals(subId) && ObjectUtil.isNotEmpty(sub.get("targetClassify"))) {
//                                targetClassify = sub.get("targetClassify").toString();
//                                subtargetname = sub.get("targetName").toString();
//                            }
//                            if (ObjectUtil.isNotEmpty(sub.get("targetClassify")) && sub.get("targetClassify").toString().equals(targetType.getTypeId())) {
//                                Map<String, Object> m = new HashMap<>();
//                                m.put("name", sub.get("targetName"));
//                                m.put("value", 0);
//                                if (CollectionUtil.isNotEmpty(valueData)) {
//                                    for (ValueData valueDatum : valueData) {
//                                        if (valueDatum.getSubId().equals(sub.get("subId").toString())) {
//                                            m.put("value", valueDatum.getScore());
//                                            break;
//                                        }
//                                    }
//                                }
//                                subDataList.add(m);
//                            }
//                        }
//                        if (CollectionUtil.isNotEmpty(subDataList)) {
//                            map.put("data", subDataList);
//                            dataList.add(map);
//                        }
//                    }
//                }
                //判断打击后目标列表
//                List<Map<String, Object>> datasList = new ArrayList<>();
//                if (CollectionUtil.isNotEmpty(subList)) {
//                    for (TargetType targetType : type) {
//                        Map<String, Object> map = new HashMap<>();
//                        map.put("name", targetType.getTypeName());
//                        List<Map<String, Object>> subDataList = new ArrayList<>();
//                        for (Map<String, Object> sub : subList) {
//                            if (subId.equals(sub.get("subId").toString())) {
//                                continue;
//                            }
//                            if (ObjectUtil.isNotEmpty(sub.get("targetClassify")) && sub.get("targetClassify").toString().equals(targetType.getTypeId())) {
//                                Map<String, Object> m = new HashMap<>();
//                                m.put("name", sub.get("targetName"));
//                                m.put("value", 0);
//                                if (CollectionUtil.isNotEmpty(valueData)) {
//                                    for (ValueData valueDatum : valueData) {
//                                        if (valueDatum.getSubId().equals(sub.get("subId").toString())) {
//                                            m.put("value", valueDatum.getScore());
//                                            break;
//                                        }
//                                    }
//                                }
//                                subDataList.add(m);
//                            }
//                        }
//                        if (CollectionUtil.isNotEmpty(subDataList)) {
//                            map.put("data", subDataList);
//                            datasList.add(map);
//                        }
//                    }
//                }
//                Map<String, Object> infoMap = new HashMap<>();
//                infoMap.put("data", dataList);
//                infoMap.put("datas", datasList);
                crucialMap.put("subtargetname", subtargetname);
                if (StringUtils.isNotBlank(targetClassify)) {
                    KnowData knowData = knowMapper.selectKnowTargetOne(targetClassify, "武器选择");
                    if (null != knowData) {
                        weaptool = knowMapper.selectWeaponName(knowData.getWeapon());
                    }
                }
                crucialMap.put("weaptool", weaptool);
                crucialMap.put("djqmbnlz", new BigDecimal(djhmbnlz).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN));
                crucialMap.put("djhmbnlz", djhmbnlz != 0 ? new BigDecimal(total - djhmbnlz).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN) : 0);
                crucialMap.put("total", new BigDecimal(total).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN));
//                resultMap.put("datainfo", infoMap);
                resultMap.put("targetinfolist", crucialMap);
            }
        } catch (Exception e) {
            log.error("打击分析异常", e);
        }
        return resultMap;
    }

    @Override
    public Result selectAnalyzeMap(String targetId, int type) {
        Map<String, Object> resultMap = new HashMap<>();
        TargetData only = targetMapper.findTargetOnly(targetId);
        if (null == only || only.getDeleteSign() == 0) {
            resultMap.put("targetinfo", new HashMap<>());
            resultMap.put("subinfolist", new ArrayList<>());
            if (type == 4) {
                return ResultUtil.success(new ArrayList<>());
            }
            return ResultUtil.success(resultMap);
        }
        //主目标分析
        Map<String, Object> mainMap = mainTargetAnalyze(only, type, true);
        List<Map<String, Object>> subList = subAnalyze(this.keyWordSystem.getFILE_URL() + only.getSqliteUrl(), type, true);
        subList.addAll(weaponAnalyze(targetId));
        Map<String, Object> max = knowMapper.selectValueMaxId("003", "003", targetId);
        resultMap.put("targetinfo", mainMap);
        if (type == 3 || type == 4) {
            if (CollectionUtil.isNotEmpty(subList)) {
                if (CollectionUtil.isNotEmpty(max)) {
                    for (Map<String, Object> map : subList) {
                        if (map.get("subId").toString().equals(max.get("subId").toString())) {
                            map.put("crucial", true);
                        } else {
                            map.put("crucial", false);
                        }
                    }
                } else {
                    for (Map<String, Object> map : subList) {
                        map.put("crucial", false);
                    }
                }
            }
        }
        resultMap.put("subinfolist", subList);
        if (type == 4) {
            if (CollectionUtil.isEmpty(subList)) {
                subList = new ArrayList<>();
            }
            mainMap.put("crucial", false);
            subList.add(mainMap);
            return ResultUtil.success(subList);
        }
        return ResultUtil.success(resultMap);
    }

    /**
     * 系统分析结构/功能/特性
     *
     * @param sId
     * @param type
     * @return
     */
    @Override
    public Result selectSystemAnalyze(String sId, int type) {
//        Map<String, Object> resultMap = new HashMap<>();
        SystemMaster only = systemMasterMapper.selectSystemOnly(sId);
        if (null == only) {
            return ResultUtil.success(new ArrayList<>());
        }
        return systemAnalyze(only, type);
//        if (null == only) {
//            resultMap.put("targetinfo", new HashMap<>());
//            resultMap.put("subinfolist", new ArrayList<>());
//            return ResultUtil.success(resultMap);
//        }
//        //主目标分析
//        Map<String, Object> mainMap = mainSystemAnalyze(only, type);
//        List<Map<String, Object>> subList = mainSystemTargetAnalyze(only.getSId(), type, true);
//        resultMap.put("targetinfo", mainMap);
//        resultMap.put("subinfolist", subList);
//        return ResultUtil.success(resultMap);
    }

    @Override
    public Result selectSystemCrucialAnalyze(String sId) {
        Map<String, Object> resultMap = new HashMap<>();
        Map<String, Object> maps = new HashMap<>();
        maps.put("subtargetname", "");
        maps.put("mbnlz", 10);
        maps.put("shnlz", 0);
        Map<String, Object> map = knowMapper.selectValueMaxTargetId(sId);
        if (CollectionUtil.isNotEmpty(map)) {
            if (null != map.get("target_id")) {
                TargetData only = targetMapper.findTargetOnly(map.get("target_id").toString());
                if (null != only) {
                    maps.put("subtargetname", only.getTargetName());
                    if (ObjectUtil.isNotEmpty(map.get("goal"))) {
                        maps.put("shnlz", 10 - FileElseUtil.getStringTransitionDouble(map.get("goal").toString()));
                    }
                }
            }
        }
        resultMap.put("targetinfolist", maps);
        resultMap.put("data", new ArrayList<>());
        return ResultUtil.success(resultMap);
    }

    @Override
    public Map<String, Object> selectSystemBlowAnalyze(String sId) {
        Map<String, Object> resultMap = new HashMap<>();
        Map<String, Object> maps = new HashMap<>();
        String weaponTool = "";
        maps.put("subtargetname", "");
        maps.put("djqmbnlz", 10);
        maps.put("djhmbnlz", 0);
        maps.put("weaptool", "");
        Map<String, Object> map = knowMapper.selectValueMaxTargetId(sId);
        if (CollectionUtil.isNotEmpty(map)) {
            if (null != map.get("target_id")) {
                TargetData only = targetMapper.findTargetOnly(map.get("target_id").toString());
                if (null != only) {
                    Map<String, Object> subMaps = knowMapper.selectValueMaxTargetSubId(sId, only.getTargetId());
                    try {
                        if (ObjectUtil.isNotEmpty(subMaps.get("sub_id"))) {
                            Map<String, Object> subMap = repo.selectTargetSub(this.keyWordSystem.getFILE_URL() + only.getSqliteUrl(), subMaps.get("sub_id").toString());
                            if (null != subMap.get("targetClassify")) {
                                KnowData knowData = knowMapper.selectKnowTargetOne(subMap.get("targetClassify").toString(), "武器选择");
                                if (null != knowData) {
                                    weaponTool = knowMapper.selectWeaponName(knowData.getWeapon());
                                    maps.put("weaptool", weaponTool);
                                }
                            }
                        }
                    } catch (SQLException sqlException) {
                        sqlException.printStackTrace();
                    }
                    maps.put("subtargetname", only.getTargetName());
                    if (ObjectUtil.isNotEmpty(map.get("goal"))) {
                        maps.put("djhmbnlz", new BigDecimal(10 - Double.valueOf(map.get("goal").toString())).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN));
                    }
                }
            }
        }
        resultMap.put("datainfo", new HashMap<>());
        resultMap.put("blowInfolist", maps);
        resultMap.put("weaptool", weaponTool);
        return resultMap;
    }

    @Override
    public Result selectSystemYH(String sid, boolean system) {
        Map<String, Object> resultMap = new HashMap<>();
        List<String> yh = element.getYh();
        String yh1 = yh.get(0);
        String yh2 = yh.get(1);
        String yh3 = yh.get(2);
        String yh4 = yh.get(3);
        String yh5 = yh.get(4);
        //DY目标ID
        Map<String, Object> map = null;
        if (system) {
            map = knowMapper.selectValueMaxTargetId(sid);
        } else {
            map = knowMapper.selectValueMaxSId(sid);
        }
        String targetId = null != map ? system ? map.get("target_id").toString() : map.get("s_id").toString() : null;
        List<Map<String, Object>> list = knowMapper.selectYHInit(sid, null);
        //增加武器库分析数据
        List<Map<String, String>> weapon = knowMapper.selectYHInitWeapon(sid, null);
        if (CollectionUtil.isNotEmpty(weapon)) {
            Map<String, Object> m = null;
            for (Map<String, String> integerDoubleMap : weapon) {
                boolean juageYH = true;
                switch (integerDoubleMap.get("know_id")) {
                    case "1":
                        for (Map<String, Object> stringObjectMap : list) {
                            if (stringObjectMap.get("kind").toString().equals(yh1)) {
                                Double value = Double.valueOf(stringObjectMap.get("value").toString());
                                stringObjectMap.put("value", value + Double.valueOf(integerDoubleMap.get("goal")));
                                juageYH = false;
                                break;
                            }
                        }
                        if (juageYH) {
                            m = new HashMap<>();
                            m.put("kind", yh1);
                            m.put("value", integerDoubleMap.get("goal"));
                            list.add(m);
                        }
                        break;
                    case "2":
                        for (Map<String, Object> stringObjectMap : list) {
                            if (stringObjectMap.get("kind").toString().equals(yh2)) {
                                Double value = Double.valueOf(stringObjectMap.get("value").toString());
                                stringObjectMap.put("value", value + Double.valueOf(integerDoubleMap.get("goal")));
                                juageYH = false;
                                break;
                            }
                        }
                        if (juageYH) {
                            m = new HashMap<>();
                            m.put("kind", yh2);
                            m.put("value", integerDoubleMap.get("goal"));
                            list.add(m);
                        }
                        break;
                    case "3":
                        for (Map<String, Object> stringObjectMap : list) {
                            if (stringObjectMap.get("kind").toString().equals(yh3)) {
                                Double value = Double.valueOf(stringObjectMap.get("value").toString());
                                stringObjectMap.put("value", value + Double.valueOf(integerDoubleMap.get("goal")));
                                juageYH = false;
                                break;
                            }
                        }
                        if (juageYH) {
                            m = new HashMap<>();
                            m.put("kind", yh3);
                            m.put("value", integerDoubleMap.get("goal"));
                            list.add(m);
                        }
                        break;
                    case "4":
                        for (Map<String, Object> stringObjectMap : list) {
                            if (stringObjectMap.get("kind").toString().equals(yh4)) {
                                Double value = Double.valueOf(stringObjectMap.get("value").toString());
                                stringObjectMap.put("value", value + Double.valueOf(integerDoubleMap.get("goal")));
                                juageYH = false;
                                break;
                            }
                        }
                        if (juageYH) {
                            m = new HashMap<>();
                            m.put("kind", yh4);
                            m.put("value", integerDoubleMap.get("goal"));
                            list.add(m);
                        }
                        break;
                    case "5":
                        for (Map<String, Object> stringObjectMap : list) {
                            if (stringObjectMap.get("kind").toString().equals(yh5)) {
                                Double value = Double.valueOf(stringObjectMap.get("value").toString());
                                stringObjectMap.put("value", value + Double.valueOf(integerDoubleMap.get("goal")));
                                juageYH = false;
                                break;
                            }
                        }
                        if (juageYH) {
                            m = new HashMap<>();
                            m.put("kind", yh5);
                            m.put("value", integerDoubleMap.get("goal"));
                            list.add(m);
                        }
                        break;
                    default:
                        continue;
                }
            }
        }
        if (CollectionUtil.isNotEmpty(list)) {
            Double d = 0D;
            Double t = 0D;
            Double f = 0D;
            Double k = 0D;
            Double q = 0D;
            Integer max = 0;
            for (Map<String, Object> maps : list) {
                Double value = Double.valueOf(maps.get("value").toString());
                if (maps.get("kind").toString().equals(yh1)) {
                    d = value;
                } else if (maps.get("kind").toString().equals(yh2)) {
                    t = value;
                } else if (maps.get("kind").toString().equals(yh3)) {
                    f = value;
                } else if (maps.get("kind").toString().equals(yh4)) {
                    k = value;
                } else if (maps.get("kind").toString().equals(yh5)) {
                    q = value;
                }
                if (value > max) {
                    max = value.intValue();
                }
            }
            if (max == 0) {
                max = 1;
            } else {
                max = max + 2;
            }
            //DY后
            if (StringUtils.isNotBlank(targetId) && system) {
                Double db = 0D;
                Double tb = 0D;
                Double fb = 0D;
                Double kb = 0D;
                Double qb = 0D;
                List<Map<String, Object>> listdy = knowMapper.selectYHInit(sid, targetId);
                //增加武器库分析数据
                weapon = knowMapper.selectYHInitWeapon(sid, targetId);
                if (CollectionUtil.isNotEmpty(weapon)) {
                    Map<String, Object> m = null;
                    for (Map<String, String> integerDoubleMap : weapon) {
                        boolean juageYH = true;
                        switch (integerDoubleMap.get("know_id")) {
                            case "1":
                                for (Map<String, Object> stringObjectMap : list) {
                                    if (stringObjectMap.get("kind").toString().equals(yh1)) {
                                        Double value = Double.valueOf(stringObjectMap.get("value").toString());
                                        stringObjectMap.put("value", value + Double.valueOf(integerDoubleMap.get("goal")));
                                        juageYH = false;
                                        break;
                                    }
                                }
                                if (juageYH) {
                                    m = new HashMap<>();
                                    m.put("kind", yh1);
                                    m.put("value", integerDoubleMap.get("goal"));
                                    listdy.add(m);
                                }
                                break;
                            case "2":
                                for (Map<String, Object> stringObjectMap : list) {
                                    if (stringObjectMap.get("kind").toString().equals(yh2)) {
                                        Double value = Double.valueOf(stringObjectMap.get("value").toString());
                                        stringObjectMap.put("value", value + Double.valueOf(integerDoubleMap.get("goal")));
                                        juageYH = false;
                                        break;
                                    }
                                }
                                if (juageYH) {
                                    m = new HashMap<>();
                                    m.put("kind", yh2);
                                    m.put("value", integerDoubleMap.get("goal"));
                                    listdy.add(m);
                                }
                                break;
                            case "3":
                                for (Map<String, Object> stringObjectMap : list) {
                                    if (stringObjectMap.get("kind").toString().equals(yh3)) {
                                        Double value = Double.valueOf(stringObjectMap.get("value").toString());
                                        stringObjectMap.put("value", value + Double.valueOf(integerDoubleMap.get("goal")));
                                        juageYH = false;
                                        break;
                                    }
                                }
                                if (juageYH) {
                                    m = new HashMap<>();
                                    m.put("kind", yh3);
                                    m.put("value", integerDoubleMap.get("goal"));
                                    listdy.add(m);
                                }
                                break;
                            case "4":
                                for (Map<String, Object> stringObjectMap : list) {
                                    if (stringObjectMap.get("kind").toString().equals(yh4)) {
                                        Double value = Double.valueOf(stringObjectMap.get("value").toString());
                                        stringObjectMap.put("value", value + Double.valueOf(integerDoubleMap.get("goal")));
                                        juageYH = false;
                                        break;
                                    }
                                }
                                if (juageYH) {
                                    m = new HashMap<>();
                                    m.put("kind", yh4);
                                    m.put("value", integerDoubleMap.get("goal"));
                                    listdy.add(m);
                                }
                                break;
                            case "5":
                                for (Map<String, Object> stringObjectMap : list) {
                                    if (stringObjectMap.get("kind").toString().equals(yh5)) {
                                        Double value = Double.valueOf(stringObjectMap.get("value").toString());
                                        stringObjectMap.put("value", value + Double.valueOf(integerDoubleMap.get("goal")));
                                        juageYH = false;
                                        break;
                                    }
                                }
                                if (juageYH) {
                                    m = new HashMap<>();
                                    m.put("kind", yh5);
                                    m.put("value", integerDoubleMap.get("goal"));
                                    listdy.add(m);
                                }
                                break;
                            default:
                                continue;
                        }
                    }
                }
                if (CollectionUtil.isNotEmpty(listdy)) {
                    for (Map<String, Object> maps : listdy) {
                        if (maps.get("kind").toString().equals(yh1)) {
                            db = Double.valueOf(maps.get("value").toString());
                        } else if (maps.get("kind").toString().equals(yh2)) {
                            tb = Double.valueOf(maps.get("value").toString());
                        } else if (maps.get("kind").toString().equals(yh3)) {
                            fb = Double.valueOf(maps.get("value").toString());
                        } else if (maps.get("kind").toString().equals(yh4)) {
                            kb = Double.valueOf(maps.get("value").toString());
                        } else if (maps.get("kind").toString().equals(yh5)) {
                            qb = Double.valueOf(maps.get("value").toString());
                        }
                    }
                }
                List<BigDecimal> asList = Arrays.asList(new BigDecimal(d - db).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN),
                        new BigDecimal(t - tb).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN),
                        new BigDecimal(f - fb).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN),
                        new BigDecimal(k - kb).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN),
                        new BigDecimal(q - qb).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN));
                resultMap.put("yData", asList);
                resultMap.put("inData", asList);
            } else if (StringUtils.isNotBlank(targetId) && !system) {
                List<String> targetList = knowMapper.valueSystemsSystemTargetList(sid, targetId);
                Double db = 0D;
                Double tb = 0D;
                Double fb = 0D;
                Double kb = 0D;
                Double qb = 0D;
                if (CollectionUtil.isNotEmpty(targetList)) {
                    for (String s : targetList) {
                        List<Map<String, Object>> listdy = knowMapper.selectYHSystemInit(sid, targetId, s);
                        if (CollectionUtil.isNotEmpty(listdy)) {
                            for (Map<String, Object> maps : listdy) {
                                if (maps.get("kind").toString().equals(yh1)) {
                                    db += Double.valueOf(maps.get("value").toString());
                                } else if (maps.get("kind").toString().equals(yh2)) {
                                    tb += Double.valueOf(maps.get("value").toString());
                                } else if (maps.get("kind").toString().equals(yh3)) {
                                    fb += Double.valueOf(maps.get("value").toString());
                                } else if (maps.get("kind").toString().equals(yh4)) {
                                    kb += Double.valueOf(maps.get("value").toString());
                                } else if (maps.get("kind").toString().equals(yh5)) {
                                    qb += Double.valueOf(maps.get("value").toString());
                                }
                            }
                        }
                    }
                }
                List<BigDecimal> asList = Arrays.asList(new BigDecimal(d - db).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN),
                        new BigDecimal(t - tb).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN),
                        new BigDecimal(f - fb).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN),
                        new BigDecimal(k - kb).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN),
                        new BigDecimal(q - qb).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN));
                resultMap.put("yData", asList);
                resultMap.put("inData", asList);
            } else {
                resultMap.put("yData", Arrays.asList(d, t, f, k, q));
                resultMap.put("inData", Arrays.asList(d, t, f, k, q));
            }
            resultMap.put("outData", Arrays.asList(d, t, f, k, q));
            List<Map<String, Object>> indicator = new ArrayList<>();
            for (int i = 0; i < 5; i++) {
                Map<String, Object> maps = new HashMap<>();
                if (i == 0) {
                    maps.put("name", yh1);
                    maps.put("max", max);
                } else if (i == 1) {
                    maps.put("name", yh2);
                    maps.put("max", max);
                } else if (i == 2) {
                    maps.put("name", yh3);
                    maps.put("max", max);
                } else if (i == 3) {
                    maps.put("name", yh4);
                    maps.put("max", max);
                } else if (i == 4) {
                    maps.put("name", yh5);
                    maps.put("max", max);
                }
                indicator.add(maps);
            }
            resultMap.put("indicator", indicator);
            resultMap.put("barData", Arrays.asList(max, max, max, max, max));
        } else {
            List<Map<String, Object>> indicator = new ArrayList<>();
            for (int i = 0; i < 5; i++) {
                Map<String, Object> maps = new HashMap<>();
                if (i == 0) {
                    maps.put("name", yh1);
                    maps.put("max", 100);
                } else if (i == 1) {
                    maps.put("name", yh2);
                    maps.put("max", 100);
                } else if (i == 2) {
                    maps.put("name", yh3);
                    maps.put("max", 100);
                } else if (i == 3) {
                    maps.put("name", yh4);
                    maps.put("max", 100);
                } else if (i == 4) {
                    maps.put("name", yh5);
                    maps.put("max", 100);
                }
                indicator.add(maps);
            }
            resultMap.put("indicator", indicator);
            resultMap.put("outData", Arrays.asList(0, 0, 0, 0, 0));
            resultMap.put("inData", Arrays.asList(0, 0, 0, 0, 0));
            resultMap.put("yData", Arrays.asList(0, 0, 0, 0, 0));
            resultMap.put("barData", Arrays.asList(100, 100, 100, 100, 100));
        }
        resultMap.put("xData", Arrays.asList(yh1, yh2, yh3, yh4, yh5));
        //下
        Map<String, Object> maps = new HashMap<>();
        maps.put("subtargetname", "");
        maps.put("mbnlz", 10);
        maps.put("shnlz", 0);
        maps.put("weaptool", "");
        maps.put("remark", "暂无结论生成");
//        Map<String, Object> m = null;
//        if (system) {
//            m = selectSystemBlowAnalyze(sid);
//        } else {
//            m = selectSystemsBlowAnalyze(sid);
//        }
//        if (CollectionUtil.isNotEmpty(m)) {
//            maps.put("weaptool", m.get("weaptool"));
//        }
        maps.put("weaptool", getWeapon(sid));
        if (CollectionUtil.isNotEmpty(map)) {
            if (null != map.get("target_id") && system) {
                TargetData only = targetMapper.findTargetOnly(map.get("target_id").toString());
                if (null != only) {
                    maps.put("subtargetname", only.getTargetName());
                }
            } else if (null != map.get("s_id") && !system) {
                if (map.get("s_id").toString().equals("002")) {
                    maps.put("subtargetname", "其他");
                } else {
                    SystemMaster systemMaster = systemMasterMapper.selectSystemOnly(map.get("s_id").toString());
                    if (null != systemMaster) {
                        maps.put("subtargetname", systemMaster.getSystemName());
                    }
                }
            }
            if (ObjectUtil.isNotEmpty(map.get("goal"))) {
                double end = FileElseUtil.getStringTransitionDouble(map.get("goal").toString());
                maps.put("shnlz", new BigDecimal(10 - end).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
                if (end != 0) {
                    double v = end / 10.0;
                    if (v <= 0.2) {
                        if (system) {
                            maps.put("remark", "对该系统造成轻度毁伤效果");
                        } else {
                            maps.put("remark", "对该体系造成轻度毁伤效果");
                        }
                    } else if (v <= 0.6) {
                        if (system) {
                            maps.put("remark", "对该系统造成中度毁伤效果");
                        } else {
                            maps.put("remark", "对该体系造成中度毁伤效果");
                        }
                    } else if (v <= 0.8) {
                        if (system) {
                            maps.put("remark", "对该系统造成重度毁伤效果");
                        } else {
                            maps.put("remark", "对该体系造成重度毁伤效果");
                        }
                    } else {
                        if (system) {
                            maps.put("remark", "对该系统造成完全毁伤效果");
                        } else {
                            maps.put("remark", "对该体系造成完全毁伤效果");
                        }
                    }
                }
            }
        }
        resultMap.put("targetinfolist", maps);
        return ResultUtil.success(resultMap);
    }

    /**
     *@author zhangxuan
     *@Description TODO 获取系统体系要害目标武器
     *@Date 10:46 2022/7/8
     *@Param [id]
     *@return java.lang.String
     **/
    private String getWeapon(String id) {
        Map<String, Object> map = knowMapper.selectValueMaxTargetId(id);
        if (CollectionUtil.isNotEmpty(map)) {
            TargetData targetId = targetMapper.findTargetOnly(map.get("target_id").toString());
            if (ObjectUtil.isNotEmpty(targetId)) {
                Map<String, Object> subId = knowMapper.selectValueMaxsIdSubId(map.get("rel_id").toString(), map.get("s_id").toString(), map.get("target_id").toString());
                if (CollectionUtil.isNotEmpty(subId)) {
                    WeaponRelation weaponRelation = weaponHouseMapper.selectWeaponTargetRelationOnly(subId.get("sub_id").toString());
                    if (ObjectUtil.isNotEmpty(weaponRelation)) {
                        return "武器库数据暂不支持匹配武器";
                    }
                    try {
                        String classify = null;
                        List<Map<String, Object>> list = repo.selectTargetSubData(this.keyWordSystem.getFILE_URL() + targetId.getSqliteUrl(), Arrays.asList("targetClassify"));
                        if (CollectionUtil.isNotEmpty(list)) {
                            for (Map<String, Object> sMap : list) {
                                if (sMap.get("subId").toString().equals(subId.get("sub_id").toString())) {
                                    classify = sMap.get("targetClassify").toString();
                                    break;
                                }
                            }
                        }
                        if (StringUtils.isNotBlank(classify)) {
                            KnowData knowData = knowMapper.selectKnowTargetOne(classify, "武器选择");
                            if (ObjectUtil.isNotEmpty(knowData)) {
                                return knowMapper.selectWeaponName(knowData.getWeapon());
                            }
                        }
                    } catch (SQLException sqlException) {
                        sqlException.printStackTrace();
                    }
                }
            }
        }
        return "";
    }

    @Override
    public Result selectSystemYHInit(String sid) {
        Map<String, Object> resultMap = new HashMap<>();
        List<String> yh = element.getYh();
        String yh1 = yh.get(0);
        String yh2 = yh.get(1);
        String yh3 = yh.get(2);
        String yh4 = yh.get(3);
        String yh5 = yh.get(4);
        List<Map<String, Object>> list = knowMapper.selectYHInit(sid, null);
        //增加武器库分析数据
        List<Map<String, String>> weapon = knowMapper.selectYHInitWeapon(sid, null);
        if (CollectionUtil.isNotEmpty(weapon)) {
            Map<String, Object> m = null;
            for (Map<String, String> integerDoubleMap : weapon) {
                boolean juageYH = true;
                switch (integerDoubleMap.get("know_id")) {
                    case "1":
                        for (Map<String, Object> stringObjectMap : list) {
                            if (stringObjectMap.get("kind").toString().equals(yh1)) {
                                Double value = Double.valueOf(stringObjectMap.get("value").toString());
                                stringObjectMap.put("value", value + Double.valueOf(integerDoubleMap.get("goal")));
                                juageYH = false;
                                break;
                            }
                        }
                        if (juageYH) {
                            m = new HashMap<>();
                            m.put("kind", yh1);
                            m.put("value", integerDoubleMap.get("goal"));
                            list.add(m);
                        }
                        break;
                    case "2":
                        for (Map<String, Object> stringObjectMap : list) {
                            if (stringObjectMap.get("kind").toString().equals(yh2)) {
                                Double value = Double.valueOf(stringObjectMap.get("value").toString());
                                stringObjectMap.put("value", value + Double.valueOf(integerDoubleMap.get("goal")));
                                juageYH = false;
                                break;
                            }
                        }
                        if (juageYH) {
                            m = new HashMap<>();
                            m.put("kind", yh2);
                            m.put("value", integerDoubleMap.get("goal"));
                            list.add(m);
                        }
                        break;
                    case "3":
                        for (Map<String, Object> stringObjectMap : list) {
                            if (stringObjectMap.get("kind").toString().equals(yh3)) {
                                Double value = Double.valueOf(stringObjectMap.get("value").toString());
                                stringObjectMap.put("value", value + Double.valueOf(integerDoubleMap.get("goal")));
                                juageYH = false;
                                break;
                            }
                        }
                        if (juageYH) {
                            m = new HashMap<>();
                            m.put("kind", yh3);
                            m.put("value", integerDoubleMap.get("goal"));
                            list.add(m);
                        }
                        break;
                    case "4":
                        for (Map<String, Object> stringObjectMap : list) {
                            if (stringObjectMap.get("kind").toString().equals(yh4)) {
                                Double value = Double.valueOf(stringObjectMap.get("value").toString());
                                stringObjectMap.put("value", value + Double.valueOf(integerDoubleMap.get("goal")));
                                juageYH = false;
                                break;
                            }
                        }
                        if (juageYH) {
                            m = new HashMap<>();
                            m.put("kind", yh4);
                            m.put("value", integerDoubleMap.get("goal"));
                            list.add(m);
                        }
                        break;
                    case "5":
                        for (Map<String, Object> stringObjectMap : list) {
                            if (stringObjectMap.get("kind").toString().equals(yh5)) {
                                Double value = Double.valueOf(stringObjectMap.get("value").toString());
                                stringObjectMap.put("value", value + Double.valueOf(integerDoubleMap.get("goal")));
                                juageYH = false;
                                break;
                            }
                        }
                        if (juageYH) {
                            m = new HashMap<>();
                            m.put("kind", yh5);
                            m.put("value", integerDoubleMap.get("goal"));
                            list.add(m);
                        }
                        break;
                    default:
                        continue;
                }
            }
        }
        if (CollectionUtil.isNotEmpty(list)) {
            Double d = 0D;
            Double t = 0D;
            Double f = 0D;
            Double k = 0D;
            Double q = 0D;
            Integer max = 0;
            for (Map<String, Object> map : list) {
                Double value = Double.valueOf(map.get("value").toString());
                if (map.get("kind").toString().equals(yh1)) {
                    d = value;
                } else if (map.get("kind").toString().equals(yh2)) {
                    t = value;
                } else if (map.get("kind").toString().equals(yh3)) {
                    f = value;
                } else if (map.get("kind").toString().equals(yh4)) {
                    k = value;
                } else if (map.get("kind").toString().equals(yh5)) {
                    q = value;
                }
                if (value > max) {
                    max = value.intValue();
                }
            }
            if (max == 0) {
                max = 1;
            } else {
                max = max + 2;
            }
            resultMap.put("yData", Arrays.asList(
                    new BigDecimal(d).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN),
                    new BigDecimal(t).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN),
                    new BigDecimal(f).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN),
                    new BigDecimal(k).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN),
                    new BigDecimal(q).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN)));
            resultMap.put("barData", Arrays.asList(max, max, max, max, max));
        } else {
            resultMap.put("yData", Arrays.asList(0, 0, 0, 0, 0));
            resultMap.put("barData", Arrays.asList(100, 100, 100, 100, 100));
        }
        resultMap.put("xData", Arrays.asList(yh1, yh2, yh3, yh4, yh5));
        return ResultUtil.success(resultMap);
    }

    @Override
    public Result selectSystemAnalyzeMap(String sId, int type) {
        SystemMaster only = systemMasterMapper.selectSystemOnly(sId);
        if (null == only) {
            return ResultUtil.success(new ArrayList<>());
        }
        //子目标要害分析
//        if (type == 4) {
//            List<Map<String, Object>> resultList = new ArrayList<>();
//            resultList.addAll(mainSystemTargetAnalyze(only.getSId(), type, true));
//            Map<String, Object> subInfo = new HashMap<>();
//            Map<String, Object> map = knowMapper.selectValueMaxTargetId(sId);
//            if (CollectionUtil.isNotEmpty(map)) {
//                Map<String, Object> subMap = knowMapper.selectValueMaxTargetSubId(sId, map.get("target_id").toString());
//                if (CollectionUtil.isNotEmpty(subMap)) {
//                    TargetData targetData = targetMapper.findTargetOnly(subMap.get("target_id").toString());
//                    if (null != targetData) {
//                        try {
//                            Map<String, Object> oMap = repo.selectTargetSub(this.keyWordSystem.getFILE_URL() + targetData.getSqliteUrl(), subMap.get("sub_id").toString());
//                            subInfo.put("targetName", oMap.get("targetName"));
//                            subInfo.put("position", null != oMap.get("position") ? FileElseUtil.getStringTransitionList(oMap.get("position").toString()) : "[]");
//                            subInfo.put("height", oMap.get("height"));
//                            subInfo.put("area", oMap.get("area"));
//                            subInfo.put("plotinfoobj", oMap.get("plotinfoobj"));
//                            subInfo.put("crucial", true);
//                        } catch (SQLException sqlException) {
//                            sqlException.printStackTrace();
//                        }
//                    }
//                }
//            }
//            if (CollectionUtil.isNotEmpty(subInfo)) {
//                resultList.add(subInfo);
//            }
//            return ResultUtil.success(resultList);
//        }
        return ResultUtil.success(mainSystemTargetAnalyze(only.getSId(), type, true));
    }

    @Override
    public Result selectSystemsAnalyze(String sysId, int type) {
//        Map<String, Object> resultMap = new HashMap<>();
        SystemsMaster only = systemsMasterMapper.selectSystemsOnly(sysId);
        if (null == only) {
            return ResultUtil.success(new ArrayList<>());
        }
        return systemsAnalyze(only, type);
//        if (null == only) {
//            resultMap.put("targetinfo", new HashMap<>());
//            resultMap.put("subinfolist", new ArrayList<>());
//            return ResultUtil.success(resultMap);
//        }
//        //主目标分析
//        Map<String, Object> mainMap = mainSystemsAnalyze(only, type);
//        List<Map<String, Object>> subList = mainSystemsSystemAnalyze(only, type);
//        resultMap.put("targetinfo", mainMap);
//        resultMap.put("subinfolist", subList);
//        return ResultUtil.success(resultMap);
    }

    @Override
    public Result selectSystemsCrucialAnalyze(String sysId) {
        Map<String, Object> resultMap = new HashMap<>();
        Map<String, Object> maps = new HashMap<>();
        maps.put("subtargetname", "");
        maps.put("mbnlz", 10);
        maps.put("shnlz", 0);
        Map<String, Object> map = knowMapper.selectValueMaxSystemId(sysId);
        if (CollectionUtil.isNotEmpty(map)) {
            if (null != map.get("s_id")) {
                SystemMaster systemMaster = systemMasterMapper.selectSystemOnly(map.get("s_id").toString());
                if (null != systemMaster) {
                    maps.put("subtargetname", systemMaster.getSystemName());
                    maps.put("shnlz", null != map.get("goal") ? Double.valueOf(map.get("goal").toString()) : 0);
                }
            }
        }
        resultMap.put("data", new HashMap<>());
        resultMap.put("targetinfolist", maps);
        return ResultUtil.success(resultMap);
    }

    @Override
    public Map<String, Object> selectSystemsBlowAnalyze(String sysId) {
        Map<String, Object> resultMap = new HashMap<>();
        Map<String, Object> maps = new HashMap<>();
        String weaptool = "";
        maps.put("subtargetname", "");
        maps.put("djqmbnlz", 10);
        maps.put("djhmbnlz", 0);
        maps.put("weaptool", "");
        //查询那个系统的分值最高
        Map<String, Object> map = knowMapper.selectValueMaxSystemId(sysId);
        if (CollectionUtil.isNotEmpty(map)) {
            if (null != map.get("s_id")) {
                if (map.get("s_id").toString().equals("002")) {
                    maps.put("subtargetname", "其他");
                    maps.put("djhmbnlz", null != map.get("goal") ? new BigDecimal(10 - Double.valueOf(map.get("goal").toString())).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN) : 0);
                } else {
                    SystemMaster only = systemMasterMapper.selectSystemOnly(map.get("s_id").toString());
                    if (null != only) {
                        //查询体系系统中最高目标分值
                        Map<String, Object> targetMap = knowMapper.selectValueMaxsId(sysId, only.getSId());
                        if (null != targetMap && null != targetMap.get("target_id")) {
                            TargetData targetData = targetMapper.findTargetOnly(targetMap.get("target_id").toString());
                            if (null != targetData) {
                                ////查询体系系统中最高目标的子目标分值
                                Map<String, Object> subMaps = knowMapper.selectValueMaxsIdSubId(sysId, only.getSId(), targetData.getTargetId());
                                if (null != subMaps && null != subMaps.get("sub_id")) {
                                    try {
                                        Map<String, Object> subMap = repo.selectTargetSub(this.keyWordSystem.getFILE_URL() + targetData.getSqliteUrl(), subMaps.get("sub_id").toString());
                                        if (null != subMap.get("targetClassify")) {
                                            KnowData knowData = knowMapper.selectKnowTargetOne(subMap.get("targetClassify").toString(), "武器选择");
                                            if (null != knowData) {
                                                weaptool = knowMapper.selectWeaponName(knowData.getWeapon());
                                                maps.put("weaptool", knowMapper.selectWeaponName(knowData.getWeapon()));
                                            }
                                        }
                                    } catch (SQLException sqlException) {
                                        sqlException.printStackTrace();
                                    }
                                }
                            }
                        }
                        maps.put("subtargetname", only.getSystemName());
                        maps.put("djhmbnlz", null != map.get("goal") ? new BigDecimal(10 - Double.valueOf(map.get("goal").toString())).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN) : 0);
                    }
                }
            }
        }
        resultMap.put("datainfo", new HashMap<>());
        resultMap.put("blowInfolist", maps);
        resultMap.put("weaptool", weaptool);
        return resultMap;
    }

    @Override
    public Result blowLevel(String sysId) {
        Map<String, String> map = new HashMap<>();
        Blow blow = systemsRelationMapper.getBlow(sysId);
        if (ObjectUtil.isNotEmpty(blow)) {
            map.put("targetName", blow.getTargetId());
            map.put("blowMessage", blow.getMessage());
        } else {
            map.put("targetName", "");
            map.put("blowMessage", "");
        }
        return ResultUtil.success(map);
    }

    @Override
    public Result selectSystemsAnalyzeMap(String sysId, int type) {
        SystemsMaster only = systemsMasterMapper.selectSystemsOnly(sysId);
        if (null == only) {
            return ResultUtil.success(new ArrayList<>());
        }
        //子目标要害分析
//        if (type == 4) {
//            List<Map<String, Object>> resultList = new ArrayList<>();
//            resultList.addAll(mainSystemsSystemAnalyzeMap(only, type));
//            Map<String, Object> subInfo = new HashMap<>();
//            Map<String, Object> map = knowMapper.selectValueMaxTargetId(only.getSysId());
//            if (CollectionUtil.isNotEmpty(map)) {
//                Map<String, Object> subMap = knowMapper.selectValueMaxTargetSubId(only.getSysId(), map.get("target_id").toString());
//                if (CollectionUtil.isNotEmpty(subMap)) {
//                    TargetData targetData = targetMapper.findTargetOnly(subMap.get("target_id").toString());
//                    if (null != targetData) {
//                        try {
//                            Map<String, Object> oMap = repo.selectTargetSub(this.keyWordSystem.getFILE_URL() + targetData.getSqliteUrl(), subMap.get("sub_id").toString());
//                            subInfo.put("targetName", oMap.get("targetName"));
//                            subInfo.put("position", null != oMap.get("position") ? FileElseUtil.getStringTransitionList(oMap.get("position").toString()) : "[]");
//                            subInfo.put("height", oMap.get("height"));
//                            subInfo.put("area", oMap.get("area"));
//                            subInfo.put("plotinfoobj", oMap.get("plotinfoobj"));
//                            subInfo.put("crucial", true);
//                        } catch (SQLException sqlException) {
//                            sqlException.printStackTrace();
//                        }
//                    }
//                }
//            }
//            if (CollectionUtil.isNotEmpty(subInfo)) {
//                resultList.add(subInfo);
//            }
//            return ResultUtil.success(resultList);
//        }
        return ResultUtil.success(mainSystemsSystemAnalyzeMap(only, type));
    }

    /**
     * 查询价值分析
     */
    @Override
    public Result selectValueAnalyze(String sysId, String sId, String targetId, int sign) {
        Map<String, Object> resultMap = new HashMap<>();
        List<Map<String, Object>> resultList = new ArrayList<>();
        double sum = 0D;
        if (sign == 0) {
            SystemsMaster systems = systemsMasterMapper.selectSystemsOnly(sysId);
            if (null != systems) {
                List<ValueData> valueData = knowMapper.selectSystemsValue(sysId);
                //查询系统
                if (StringUtils.isNotBlank(systems.getIncludeType())) {
                    String[] split = systems.getIncludeType().split(",");
                    for (String s : split) {
                        Map<String, Object> map = new HashMap<>();
                        SystemMaster system = systemMasterMapper.selectSystemOnly(s);
                        if (null != system) {
                            map.put("id", system.getSId());
                            map.put("systemName", system.getSystemName());
                            map.put("systemScore", 0D);
                            map.put("systemWeight", 0D);
                            map.put("lastSystemScore", 0D);
                            if (CollectionUtil.isNotEmpty(valueData)) {
                                for (ValueData valueDatum : valueData) {
                                    if (valueDatum.getSId().equals(system.getSId())) {
                                        map.put("systemScore", valueDatum.getScore());
                                        map.put("systemWeight", valueDatum.getWeight());
                                        map.put("lastSystemScore", valueDatum.getGoal());
                                        if (null != valueDatum.getGoal()) {
                                            sum += valueDatum.getGoal();
                                        }
                                        break;
                                    }
                                }
                            }
                            resultList.add(map);
                        }
                    }
                }
                //查询非系统
                int i = systemsMasterMapper.selectSystemsRelationCount(sysId, "1");
                if (i > 0) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("id", "002");
                    map.put("systemName", "其他");
                    map.put("systemScore", 0D);
                    map.put("systemWeight", 0D);
                    map.put("lastSystemScore", 0D);
                    if (CollectionUtil.isNotEmpty(valueData)) {
                        for (ValueData valueDatum : valueData) {
                            if (valueDatum.getSId().equals("002")) {
                                map.put("systemScore", valueDatum.getScore());
                                map.put("systemWeight", valueDatum.getWeight());
                                map.put("lastSystemScore", valueDatum.getGoal());
                                if (null != valueDatum.getGoal()) {
                                    sum += valueDatum.getGoal();
                                }
                                break;
                            }
                        }
                    }
                    resultList.add(map);
                }
            }
        } else if (sign == 1) {
            List<Map<String, Object>> targetIdAndName = null;
            if (sId.equals("002")) {
                targetIdAndName = systemsRelationMapper.selectNoSystemTargetList(sysId);
            } else {
                targetIdAndName = systemRelationMapper.selectSystemRelationTargetIdAndName(sId);
            }
            if (CollectionUtil.isNotEmpty(targetIdAndName)) {
                List<ValueData> valueData = knowMapper.selectSystemValue(sysId, sId);
                for (Map<String, Object> maps : targetIdAndName) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("id", maps.get("targetId").toString());
                    map.put("targetName", maps.get("targetName").toString());
                    map.put("targetScore", 0D);
                    map.put("targetWeight", 0D);
                    map.put("lastTargetScore", 0D);
                    if (CollectionUtil.isNotEmpty(valueData)) {
                        for (ValueData valueDatum : valueData) {
                            if (valueDatum.getTargetId().equals(maps.get("targetId").toString())) {
                                map.put("targetScore", valueDatum.getScore());
                                map.put("targetWeight", valueDatum.getWeight());
                                map.put("lastTargetScore", valueDatum.getGoal());
                                if (null != valueDatum.getGoal()) {
                                    sum += valueDatum.getGoal();
                                }
                                break;
                            }
                        }
                    }
                    resultList.add(map);
                }
            }

        } else if (sign == 2) {
            TargetData only = targetMapper.findTargetOnly(targetId);
            if (null != only) {
                try {
                    List<ValueData> valueData = null;
                    List<String> subData = new ArrayList<>();
                    subData.add("targetName");
                    subData.add("targetClassify");
                    //查询子目标列表
                    List<Map<String, Object>> data = repo.selectTargetSubData(this.keyWordSystem.getFILE_URL() + only.getSqliteUrl(), subData);
                    if (CollectionUtil.isNotEmpty(data)) {
                        valueData = knowMapper.selectTargetValue(sysId, sId, targetId);
                        for (Map<String, Object> datum : data) {
                            Map<String, Object> map = new HashMap<>();
                            map.put("id", datum.get("subId").toString());
                            map.put("subTargetName", datum.get("targetName"));
                            map.put("subTargetWeight", 0);
                            map.put("lastScore", 0);
                            if (CollectionUtil.isNotEmpty(valueData)) {
                                for (ValueData valueDatum : valueData) {
                                    if (null != valueDatum.getSubId() && valueDatum.getSubId().equals(datum.get("subId").toString())) {
                                        map.put("subTargetWeight", valueDatum.getWeight());
                                        map.put("lastScore", valueDatum.getGoal());
                                        if (null != valueDatum.getGoal()) {
                                            sum += valueDatum.getGoal();
                                        }
                                        break;
                                    }
                                }
                            }
                            List<Map<String, Object>> mapSub = new ArrayList<>();
                            if (null != datum.get("targetClassify")) {
                                JSONArray array = JSONArray.parseArray(datum.get("targetClassify").toString());
                                //查询单个子目标具体评分项
                                List<String> yh = element.getYh();
                                String[] kinds = {yh.get(0), yh.get(1), yh.get(2), yh.get(3), yh.get(4)};
                                List<KnowData> knowDatas = knowMapper.selectKnowTargetListByKindList(array.getString(array.size() - 1), Arrays.asList(kinds));
                                if (CollectionUtil.isNotEmpty(knowDatas)) {
                                    List<ValueData> valueSubData = knowMapper.selectSubTargetValue(sysId, sId, targetId, datum.get("subId").toString());
                                    for (KnowData knowData : knowDatas) {
                                        Map<String, Object> knowMap = new HashMap<>();
                                        knowMap.put("knowId", knowData.getId());
                                        knowMap.put("itemName", knowData.getName());
                                        knowMap.put("abilityValue", knowData.getRemark());
                                        knowMap.put("score", 0D);
                                        knowMap.put("weight", 0D);
                                        knowMap.put("lastScore", 0D);
                                        if (CollectionUtil.isNotEmpty(valueData)) {
                                            for (ValueData valueDatum : valueSubData) {
                                                if (null != valueDatum.getKnowId() && valueDatum.getKnowId().equals(knowData.getId())) {
                                                    knowMap.put("score", valueDatum.getScore());
                                                    knowMap.put("weight", valueDatum.getWeight());
                                                    knowMap.put("lastScore", valueDatum.getGoal());
                                                    break;
                                                }
                                            }
                                        }
                                        mapSub.add(knowMap);
                                    }
                                }
                            }
                            if (CollectionUtil.isNotEmpty(mapSub)) {
                                map.put("children", mapSub);
                                resultList.add(map);
                            }
                        }
                    }
                    //武器库分析
                    List<WeaponRelation> weaponRelations = weaponHouseMapper.selectWeaponTargetRelationNameByTargetId(targetId);
                    if (CollectionUtil.isNotEmpty(weaponRelations)) {
                        for (WeaponRelation weaponRelation : weaponRelations) {
                            Map<String, Object> map = new HashMap<>();
                            map.put("id", weaponRelation.getId());
                            map.put("subTargetName", weaponRelation.getWeaponId());
                            map.put("subTargetWeight", 0);
                            map.put("lastScore", 0);
                            if (CollectionUtil.isNotEmpty(valueData)) {
                                for (ValueData valueDatum : valueData) {
                                    if (null != valueDatum.getSubId() && valueDatum.getSubId().equals(weaponRelation.getId())) {
                                        map.put("subTargetWeight", valueDatum.getWeight());
                                        map.put("lastScore", valueDatum.getGoal());
                                        if (null != valueDatum.getGoal()) {
                                            sum += valueDatum.getGoal();
                                        }
                                        break;
                                    }
                                }
                            }
                            List<Map<String, Object>> mapSub = new ArrayList<>();
                            List<String> elementYh = element.getYh();
                            List<ValueData> valueSubData = knowMapper.selectSubTargetValue(sysId, sId, targetId, weaponRelation.getId());
                            for (int i = 1; i <= elementYh.size(); i++) {
                                Map<String, Object> knowMap = new HashMap<>();
                                knowMap.put("knowId", i);
                                knowMap.put("itemName", elementYh.get(i - 1));
                                knowMap.put("abilityValue", weaponRelation.getWeaponId() + "-" + elementYh.get(i - 1));
                                knowMap.put("score", 0D);
                                knowMap.put("weight", 0D);
                                knowMap.put("lastScore", 0D);
                                if (CollectionUtil.isNotEmpty(valueData)) {
                                    for (ValueData valueDatum : valueSubData) {
                                        if (null != valueDatum.getKnowId() && valueDatum.getKnowId().equals(i + "")) {
                                            knowMap.put("score", valueDatum.getScore());
                                            knowMap.put("weight", valueDatum.getWeight());
                                            knowMap.put("lastScore", valueDatum.getGoal());
                                            break;
                                        }
                                    }
                                }
                                mapSub.add(knowMap);
                            }
                            if (CollectionUtil.isNotEmpty(mapSub)) {
                                map.put("children", mapSub);
                                resultList.add(map);
                            }
                        }
                    }
                } catch (SQLException e) {
                    log.error("价值分析目标分析异常", e);
                }
            }
        }
        resultMap.put("sum", new BigDecimal(sum).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN));
        resultMap.put("dataList", resultList);
        return ResultUtil.success(resultMap);
    }

    @Override
    public Result addValue(String id, String sysId, String sId, String targetId, String knowId, Double score, Double weight) {
        if (null == weight || weight < 0 || weight > 1) {
            return ResultUtil.error(ResultEnum.WEIGHT_IS_ERROR);
        }
        if (StringUtils.isNotBlank(targetId) && StringUtils.isNotBlank(sId) && StringUtils.isNotBlank(sysId) && StringUtils.isNotBlank(knowId)) {
            if (null == score || score < 0 || score > 10) {
                return ResultUtil.error(ResultEnum.SCORE_IS_ERROR);
            }
        }
        int value = systemsValue(id, sysId, sId, targetId, knowId, score, weight);
        if (value == 0) {
            return ResultUtil.error(ResultEnum.SAVE_IS_ERROR);
        }
        return ResultUtil.success();
    }

    @Override
    public Result selectValueSystemAnalyze(String sId, String targetId, int sign) {
        Map<String, Object> resultMap = new HashMap<>();
        List<Map<String, Object>> resultList = new ArrayList<>();
        double sum = 0D;
        if (sign == 1) {
            List<Map<String, Object>> targetIdAndName = systemRelationMapper.selectSystemRelationTargetIdAndName(sId);
            if (CollectionUtil.isNotEmpty(targetIdAndName)) {
                List<ValueData> valueData = knowMapper.selectSystemValue(sId, "001");
                for (Map<String, Object> maps : targetIdAndName) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("id", maps.get("targetId").toString());
                    map.put("targetName", maps.get("targetName").toString());
                    map.put("targetScore", 0D);
                    map.put("targetWeight", 0D);
                    map.put("lastTargetScore", 0D);
                    if (CollectionUtil.isNotEmpty(valueData)) {
                        for (ValueData valueDatum : valueData) {
                            if (valueDatum.getTargetId().equals(maps.get("targetId").toString())) {
                                map.put("targetScore", valueDatum.getScore());
                                map.put("targetWeight", valueDatum.getWeight());
                                map.put("lastTargetScore", valueDatum.getGoal());
                                if (null != valueDatum.getGoal()) {
                                    sum += valueDatum.getGoal();
                                }
                                break;
                            }
                        }
                    }
                    resultList.add(map);
                }
            }
        } else if (sign == 2) {
            TargetData only = targetMapper.findTargetOnly(targetId);
            if (null != only) {
                try {
                    List<ValueData> valueData = null;
                    List<String> subData = new ArrayList<>();
                    subData.add("targetName");
                    subData.add("targetClassify");
                    //查询子目标列表
                    List<Map<String, Object>> data = repo.selectTargetSubData(this.keyWordSystem.getFILE_URL() + only.getSqliteUrl(), subData);
                    if (CollectionUtil.isNotEmpty(data)) {
                        valueData = knowMapper.selectTargetValue(sId, "001", targetId);
                        for (Map<String, Object> datum : data) {
                            Map<String, Object> map = new HashMap<>();
                            map.put("id", datum.get("subId").toString());
                            map.put("subTargetName", datum.get("targetName"));
                            map.put("subTargetWeight", 0);
                            map.put("lastScore", 0);
                            if (CollectionUtil.isNotEmpty(valueData)) {
                                for (ValueData valueDatum : valueData) {
                                    if (null != valueDatum.getSubId() && valueDatum.getSubId().equals(datum.get("subId").toString())) {
                                        map.put("subTargetWeight", valueDatum.getWeight());
                                        map.put("lastScore", valueDatum.getGoal());
                                        if (null != valueDatum.getGoal()) {
                                            sum += valueDatum.getGoal();
                                        }
                                        break;
                                    }
                                }
                            }
                            List<Map<String, Object>> mapSub = new ArrayList<>();
                            if (null != datum.get("targetClassify")) {
                                //查询单个子目标具体评分项
                                List<String> yh = element.getYh();
                                String[] kinds = {yh.get(0), yh.get(1), yh.get(2), yh.get(3), yh.get(4)};
                                List<KnowData> knowDatas = knowMapper.selectKnowTargetListByKindList(datum.get("targetClassify").toString(), Arrays.asList(kinds));
                                if (CollectionUtil.isNotEmpty(knowDatas)) {
                                    List<ValueData> valueSubData = knowMapper.selectSubTargetValue(sId, "001", targetId, datum.get("subId").toString());
                                    for (KnowData knowData : knowDatas) {
                                        Map<String, Object> knowMap = new HashMap<>();
                                        knowMap.put("knowId", knowData.getId());
                                        knowMap.put("itemName", knowData.getName());
                                        knowMap.put("abilityValue", knowData.getRemark());
                                        knowMap.put("score", 0D);
                                        knowMap.put("weight", 0D);
                                        knowMap.put("lastScore", 0D);
                                        if (CollectionUtil.isNotEmpty(valueData)) {
                                            for (ValueData valueDatum : valueSubData) {
                                                if (null != valueDatum.getKnowId() && valueDatum.getKnowId().equals(knowData.getId())) {
                                                    knowMap.put("score", valueDatum.getScore());
                                                    knowMap.put("weight", valueDatum.getWeight());
                                                    knowMap.put("lastScore", valueDatum.getGoal());
                                                    break;
                                                }
                                            }
                                        }
                                        mapSub.add(knowMap);
                                    }
                                }
                            }
                            if (CollectionUtil.isNotEmpty(mapSub)) {
                                map.put("children", mapSub);
                                resultList.add(map);
                            }
                        }
                    }
                    //武器库分析
                    List<WeaponRelation> weaponRelations = weaponHouseMapper.selectWeaponTargetRelationNameByTargetId(targetId);
                    if (CollectionUtil.isNotEmpty(weaponRelations)) {
                        for (WeaponRelation weaponRelation : weaponRelations) {
                            Map<String, Object> map = new HashMap<>();
                            map.put("id", weaponRelation.getId());
                            map.put("subTargetName", weaponRelation.getWeaponId());
                            map.put("subTargetWeight", 0);
                            map.put("lastScore", 0);
                            if (CollectionUtil.isNotEmpty(valueData)) {
                                for (ValueData valueDatum : valueData) {
                                    if (null != valueDatum.getSubId() && valueDatum.getSubId().equals(weaponRelation.getId())) {
                                        map.put("subTargetWeight", valueDatum.getWeight());
                                        map.put("lastScore", valueDatum.getGoal());
                                        if (null != valueDatum.getGoal()) {
                                            sum += valueDatum.getGoal();
                                        }
                                        break;
                                    }
                                }
                            }
                            List<Map<String, Object>> mapSub = new ArrayList<>();
                            List<String> elementYh = element.getYh();
                            List<ValueData> valueSubData = knowMapper.selectSubTargetValue(sId, "001", targetId, weaponRelation.getId());
                            for (int i = 1; i <= elementYh.size(); i++) {
                                Map<String, Object> knowMap = new HashMap<>();
                                knowMap.put("knowId", i);
                                knowMap.put("itemName", elementYh.get(i - 1));
                                knowMap.put("abilityValue", weaponRelation.getWeaponId() + "-" + elementYh.get(i - 1));
                                knowMap.put("score", 0D);
                                knowMap.put("weight", 0D);
                                knowMap.put("lastScore", 0D);
                                if (CollectionUtil.isNotEmpty(valueData)) {
                                    for (ValueData valueDatum : valueSubData) {
                                        if (null != valueDatum.getKnowId() && valueDatum.getKnowId().equals(i + "")) {
                                            knowMap.put("score", valueDatum.getScore());
                                            knowMap.put("weight", valueDatum.getWeight());
                                            knowMap.put("lastScore", valueDatum.getGoal());
                                            break;
                                        }
                                    }
                                }
                                mapSub.add(knowMap);
                            }
                            if (CollectionUtil.isNotEmpty(mapSub)) {
                                map.put("children", mapSub);
                                resultList.add(map);
                            }
                        }
                    }
                } catch (SQLException e) {
                    log.error("价值分析目标分析异常", e);
                }
            }
        }
        resultMap.put("sum", new BigDecimal(sum).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN));
        resultMap.put("dataList", resultList);
        return ResultUtil.success(resultMap);
    }

    @Override
    public Result addValueSystem(String id, String sId, String targetId, String knowId, Double score, Double weight) {
        if (null == weight || weight < 0 || weight > 1) {
            return ResultUtil.error(ResultEnum.WEIGHT_IS_ERROR);
        }
        if (StringUtils.isNotBlank(targetId) && StringUtils.isNotBlank(sId) && StringUtils.isNotBlank(knowId)) {
            if (null == score || score < 0 || score > 10) {
                return ResultUtil.error(ResultEnum.SCORE_IS_ERROR);
            }
        }
        int value = systemValue(id, sId, targetId, knowId, score, weight);
        if (value == 0) {
            return ResultUtil.error(ResultEnum.SAVE_IS_ERROR);
        }
        return ResultUtil.success();
    }

    @Override
    public Result selectValueTargetAnalyze(String targetId) {
        Map<String, Object> resultMap = new HashMap<>();
        List<Map<String, Object>> resultList = new ArrayList<>();
        double sum = 0D;
        TargetData only = targetMapper.findTargetOnly(targetId);
        if (ObjectUtil.isNotEmpty(only)) {
            List<ValueData> valueData = null;
            try {
                List<String> subData = new ArrayList<>();
                subData.add("targetName");
                subData.add("targetClassify");
                //查询子目标列表
                List<Map<String, Object>> data = repo.selectTargetSubData(this.keyWordSystem.getFILE_URL() + only.getSqliteUrl(), subData);
                if (CollectionUtil.isNotEmpty(data)) {
                    valueData = knowMapper.selectTargetValue("003", "003", targetId);
                    for (Map<String, Object> datum : data) {
                        Map<String, Object> map = new HashMap<>();
                        map.put("id", datum.get("subId").toString());
                        map.put("subTargetName", datum.get("targetName"));
                        map.put("subTargetWeight", 0);
                        map.put("lastScore", 0);
                        if (CollectionUtil.isNotEmpty(valueData)) {
                            for (ValueData valueDatum : valueData) {
                                if (null != valueDatum.getSubId() && valueDatum.getSubId().equals(datum.get("subId").toString())) {
                                    map.put("subTargetWeight", valueDatum.getWeight());
                                    map.put("lastScore", valueDatum.getGoal());
                                    if (null != valueDatum.getGoal()) {
                                        sum += valueDatum.getGoal();
                                    }
                                    break;
                                }
                            }
                        }
                        List<Map<String, Object>> mapSub = new ArrayList<>();
                        if (null != datum.get("targetClassify")) {
                            JSONArray array = JSONArray.parseArray(datum.get("targetClassify").toString());
                            //查询单个子目标具体评分项
                            List<String> yh = element.getYh();
                            String[] kinds = {yh.get(0), yh.get(1), yh.get(2), yh.get(3), yh.get(4)};
                            List<KnowData> knowDatas = knowMapper.selectKnowTargetListByKindList(array.getString(array.size() - 1), Arrays.asList(kinds));
                            if (CollectionUtil.isNotEmpty(knowDatas)) {
                                List<ValueData> valueSubData = knowMapper.selectSubTargetValue("003", "003", targetId, datum.get("subId").toString());
                                for (KnowData knowData : knowDatas) {
                                    Map<String, Object> knowMap = new HashMap<>();
                                    knowMap.put("knowId", knowData.getId());
                                    knowMap.put("itemName", knowData.getName());
                                    knowMap.put("abilityValue", knowData.getRemark());
                                    knowMap.put("score", 0D);
                                    knowMap.put("weight", 0D);
                                    knowMap.put("lastScore", 0D);
                                    if (CollectionUtil.isNotEmpty(valueData)) {
                                        for (ValueData valueDatum : valueSubData) {
                                            if (null != valueDatum.getKnowId() && valueDatum.getKnowId().equals(knowData.getId())) {
                                                knowMap.put("score", valueDatum.getScore());
                                                knowMap.put("weight", valueDatum.getWeight());
                                                knowMap.put("lastScore", valueDatum.getGoal());
                                                break;
                                            }
                                        }
                                    }
                                    mapSub.add(knowMap);
                                }
                            }
                        }
                        if (CollectionUtil.isNotEmpty(mapSub)) {
                            map.put("children", mapSub);
                            resultList.add(map);
                        }
                    }
                }
            } catch (SQLException e) {
                log.error("价值分析目标分析异常", e);
            }
            //武器库价值分析
            List<WeaponRelation> weaponRelations = weaponHouseMapper.selectWeaponTargetRelationNameByTargetId(targetId);
            if (CollectionUtil.isNotEmpty(weaponRelations)) {
                for (WeaponRelation weaponRelation : weaponRelations) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("id", weaponRelation.getId());
                    map.put("subTargetName", weaponRelation.getWeaponId());
                    map.put("subTargetWeight", 0);
                    map.put("lastScore", 0);
                    if (CollectionUtil.isNotEmpty(valueData)) {
                        for (ValueData valueDatum : valueData) {
                            if (null != valueDatum.getSubId() && valueDatum.getSubId().equals(weaponRelation.getId())) {
                                map.put("subTargetWeight", valueDatum.getWeight());
                                map.put("lastScore", valueDatum.getGoal());
                                if (null != valueDatum.getGoal()) {
                                    sum += valueDatum.getGoal();
                                }
                                break;
                            }
                        }
                    }
                    List<Map<String, Object>> mapSub = new ArrayList<>();
                    List<String> elementYh = element.getYh();
                    List<ValueData> valueSubData = knowMapper.selectSubTargetValue("003", "003", targetId, weaponRelation.getId());
                    for (int i = 1; i <= elementYh.size(); i++) {
                        Map<String, Object> knowMap = new HashMap<>();
                        knowMap.put("knowId", i);
                        knowMap.put("itemName", elementYh.get(i - 1));
                        knowMap.put("abilityValue", weaponRelation.getWeaponId() + "-" + elementYh.get(i - 1));
                        knowMap.put("score", 0D);
                        knowMap.put("weight", 0D);
                        knowMap.put("lastScore", 0D);
                        if (CollectionUtil.isNotEmpty(valueData)) {
                            for (ValueData valueDatum : valueSubData) {
                                if (null != valueDatum.getKnowId() && valueDatum.getKnowId().equals(i + "")) {
                                    knowMap.put("score", valueDatum.getScore());
                                    knowMap.put("weight", valueDatum.getWeight());
                                    knowMap.put("lastScore", valueDatum.getGoal());
                                    break;
                                }
                            }
                        }
                        mapSub.add(knowMap);
                    }
                    if (CollectionUtil.isNotEmpty(mapSub)) {
                        map.put("children", mapSub);
                        resultList.add(map);
                    }
                }
            }
        }
        resultMap.put("sum", new BigDecimal(sum).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN));
        resultMap.put("dataList", resultList);
        return ResultUtil.success(resultMap);
    }

    @Override
    public Result addValueTarget(String id, String targetId, String knowId, Double score, Double weight) {
        if (null == weight || weight < 0 || weight > 1) {
            return ResultUtil.error(ResultEnum.WEIGHT_IS_ERROR);
        }
        if (StringUtils.isNotBlank(targetId) && StringUtils.isNotBlank(knowId)) {
            if (null == score || score < 0 || score > 10) {
                return ResultUtil.error(ResultEnum.SCORE_IS_ERROR);
            }
        }
        int value = targetValue(id, targetId, knowId, score, weight);
        if (value == 0) {
            return ResultUtil.error(ResultEnum.SAVE_IS_ERROR);
        }
        return ResultUtil.success();
    }

    @Override
    public Result selectTargetAnalyzeValue(String targetId, List<Map> list) {
        Map<String, Object> resultMap = new HashMap<>();
        List<Map<String, Object>> resultList = new ArrayList<>();
        double sum = 0D;
        TargetData only = targetMapper.findTargetOnly(targetId);
        if (ObjectUtil.isNotEmpty(only)) {
            try {
                //分析要害
                Map<String, Double> valueSub = new HashMap<>();
                List<ValueData> valueData = knowMapper.selectTargetValue("003", "003", targetId);
                double max = 0D;
                String maxId = "";
                //获取要害子目标
                if (CollectionUtil.isNotEmpty(valueData)) {
                    for (ValueData valueDatum : valueData) {
                        valueSub.put(valueDatum.getSubId(), valueDatum.getScore());
                        if (valueDatum.getScore() > max) {
                            max = valueDatum.getScore();
                            maxId = valueDatum.getSubId();
                        }
                    }
                }
                //查询子目标列表
                List<String> subData = new ArrayList<>();
                subData.add("targetName");
                subData.add("targetClassify");
                List<Map<String, Object>> data = repo.selectTargetSubData(this.keyWordSystem.getFILE_URL() + only.getSqliteUrl(), subData);
                if (CollectionUtil.isNotEmpty(data)) {
                    for (Map<String, Object> datum : data) {
                        //子目标信息封装
                        Map<String, Object> map = new HashMap<>();
                        map.put("id", datum.get("subId").toString());
                        map.put("subTargetName", datum.get("targetName"));
                        if (datum.get("subId").toString().equals(maxId)) {
                            map.put("sign", true);
                        } else {
                            map.put("sign", false);
                        }
                        //子目标评分
                        double subValue = 0D;
                        if (CollectionUtil.isNotEmpty(valueSub) && valueSub.containsKey(datum.get("subId").toString())) {
                            subValue = valueSub.get(datum.get("subId").toString());
                        }
                        List<Map<String, Object>> mapSub = new ArrayList<>();
                        if (ObjectUtil.isNotEmpty(datum.get("targetClassify"))) {
                            JSONArray array = JSONArray.parseArray(datum.get("targetClassify").toString());
                            //查询单个子目标具体评分项
                            List<String> yh = element.getYh();
                            String[] kinds = {yh.get(0), yh.get(1), yh.get(2), yh.get(3), yh.get(4)};
                            List<KnowData> knowDatas = knowMapper.selectKnowTargetListByKindList(array.getString(array.size() - 1), Arrays.asList(kinds));
                            if (CollectionUtil.isNotEmpty(knowDatas)) {
                                List<ValueData> valueSubData = knowMapper.selectSubTargetValue("003", "003", targetId, datum.get("subId").toString());
                                for (KnowData knowData : knowDatas) {
                                    Map<String, Object> knowMap = new HashMap<>();
                                    knowMap.put("knowId", knowData.getId());
                                    knowMap.put("itemName", knowData.getName());
                                    knowMap.put("weight", 0D);
                                    knowMap.put("first", 0);
                                    knowMap.put("last", 0);
                                    knowMap.put("lastScore", 0D);
                                    double score = 0D;
                                    if (CollectionUtil.isNotEmpty(valueSubData)) {
                                        for (ValueData valueDatum : valueSubData) {
                                            if (valueDatum.getKnowId().equals(knowData.getId())) {
                                                knowMap.put("weight", valueDatum.getWeight());
                                                knowMap.put("first", new BigDecimal(valueDatum.getGoal()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN));
                                                knowMap.put("last", new BigDecimal(subValue - valueDatum.getGoal()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN));
                                                knowMap.put("lastScore", new BigDecimal(valueDatum.getGoal()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN));
                                                score = valueDatum.getScore();
                                                break;
                                            }
                                        }
                                    }
                                    if (CollectionUtil.isNotEmpty(list)) {
                                        for (Map<String, Object> stringObjectMap : list) {
                                            if (stringObjectMap.get("id").toString().equals(datum.get("subId"))
                                                    && stringObjectMap.get("knowId").toString().equals(knowData.getId())) {
                                                double weight = FileElseUtil.getStringTransitionDouble(stringObjectMap.get("weight").toString());
                                                knowMap.put("weight", weight);
                                                knowMap.put("first", new BigDecimal(score * weight).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN));
                                                knowMap.put("last", new BigDecimal(subValue - score * weight).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN));
                                                break;
                                            }
                                        }
                                    }
                                    mapSub.add(knowMap);
                                }
                            }
                        }
                        if (CollectionUtil.isNotEmpty(mapSub)) {
                            map.put("children", mapSub);
                            resultList.add(map);
                        }
                    }
                }
                //武器库数据分析
                List<WeaponRelation> weaponRelations = weaponHouseMapper.selectWeaponTargetRelationNameByTargetId(targetId);
                if (CollectionUtil.isNotEmpty(weaponRelations)) {
                    for (WeaponRelation weaponRelation : weaponRelations) {
                        Map<String, Object> map = new HashMap<>();
                        map.put("id", weaponRelation.getId());
                        map.put("subTargetName", weaponRelation.getWeaponId());
                        if (weaponRelation.getId().equals(maxId)) {
                            map.put("sign", true);
                        } else {
                            map.put("sign", false);
                        }
                        double subValue = 0D;
                        if (CollectionUtil.isNotEmpty(valueSub) && valueSub.containsKey(weaponRelation.getId())) {
                            subValue = valueSub.get(weaponRelation.getId());
                        }
                        List<Map<String, Object>> mapSub = new ArrayList<>();
                        List<String> elementYh = element.getYh();
                        List<ValueData> valueSubData = knowMapper.selectSubTargetValue("003", "003", targetId, weaponRelation.getId());
                        for (int i = 1; i <= elementYh.size(); i++) {
                            Map<String, Object> knowMap = new HashMap<>();
                            knowMap.put("knowId", i);
                            knowMap.put("itemName", elementYh.get(i - 1));
                            knowMap.put("weight", 0D);
                            knowMap.put("first", 0);
                            knowMap.put("last", 0);
                            knowMap.put("lastScore", 0D);
                            double score = 0D;
                            if (CollectionUtil.isNotEmpty(valueSubData)) {
                                for (ValueData valueDatum : valueSubData) {
                                    if (valueDatum.getKnowId().equals(i + "")) {
                                        knowMap.put("weight", valueDatum.getWeight());
                                        knowMap.put("first", new BigDecimal(valueDatum.getGoal()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN));
                                        knowMap.put("last", new BigDecimal(subValue - valueDatum.getGoal()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN));
                                        knowMap.put("lastScore", new BigDecimal(valueDatum.getGoal()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN));
                                        score = valueDatum.getScore();
                                        break;
                                    }
                                }
                            }
                            if (CollectionUtil.isNotEmpty(list)) {
                                for (Map<String, Object> stringObjectMap : list) {
                                    if (stringObjectMap.get("id").toString().equals(weaponRelation.getId())
                                            && stringObjectMap.get("knowId").toString().equals(i + "")) {
                                        double weight = FileElseUtil.getStringTransitionDouble(stringObjectMap.get("weight").toString());
                                        knowMap.put("weight", weight);
                                        knowMap.put("first", new BigDecimal(score * weight).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN));
                                        knowMap.put("last", new BigDecimal(subValue - score * weight).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN));
                                        break;
                                    }
                                }
                            }
                            mapSub.add(knowMap);
                        }
                        if (CollectionUtil.isNotEmpty(mapSub)) {
                            map.put("children", mapSub);
                            resultList.add(map);
                        }
                    }
                }
            } catch (SQLException e) {
                log.error("价值分析目标分析异常", e);
            }
        }
        resultMap.put("sum", new BigDecimal(sum).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN));
        resultMap.put("dataList", resultList);
        return ResultUtil.success(resultMap);
    }

    @Override
    public void deleteSystemValue(String sId) {
        List<Map<String, Object>> list = knowMapper.selectSystemValueData(sId);
        if (CollectionUtil.isNotEmpty(list)) {
            for (Map<String, Object> map : list) {
                //删除价值分析与此目标关联的数据
                systemsValue(sId, map.get("rel_id").toString(), null, null, null, 0.0, 0.0);
                knowMapper.deleteSystemIdRelation(map.get("rel_id").toString(), sId);
            }
        }
    }

    @Override
    public void deleteSystemsSystemValue(String sysId, String sId) {
        List<Map<String, Object>> list = knowMapper.selectSystemsValueData(sysId, sId);
        if (CollectionUtil.isNotEmpty(list)) {
            for (Map<String, Object> map : list) {
                //删除价值分析与此目标关联的数据
                systemsValue(sId, map.get("rel_id").toString(), null, null, null, 0.0, 0.0);
                knowMapper.deleteSystemIdRelation(map.get("rel_id").toString(), sId);
            }
        }
    }

    @Override
    public void deleteSystemTargetValue(String sId, String targetId) {
        List<Map<String, Object>> list = knowMapper.selectSystemTargetValueData(sId, "001", targetId);
        if (CollectionUtil.isNotEmpty(list)) {
            for (Map<String, Object> map : list) {
                //删除价值分析与此目标关联的数据
                systemValue(targetId, map.get("rel_id").toString(), null, null, 0.0, 0.0);
                knowMapper.deleteTargetIdRelation(map.get("rel_id").toString(), "001", targetId);
            }
        }
        List<Map<String, Object>> list1 = knowMapper.selectSystemsTargetValueData(sId, targetId);
        for (Map<String, Object> map : list1) {
            systemsValue(targetId, map.get("rel_id").toString(), map.get("s_id").toString(), null, null, 0.0, 0.0);
            knowMapper.deleteTargetIdRelation(map.get("rel_id").toString(), map.get("s_id").toString(), targetId);
        }
        //删除体系关联
        knowMapper.deleteSystemsRelation(sId, targetId);
    }

    @Override
    public void deleteSystemsTargetValue(String sysId, String targetId) {
        List<Map<String, Object>> list = knowMapper.selectSystemTargetValueData(sysId, "002", targetId);
        if (CollectionUtil.isNotEmpty(list)) {
            for (Map<String, Object> map : list) {
                systemsValue(targetId, map.get("rel_id").toString(), map.get("s_id").toString(), null, null, 0.0, 0.0);
                knowMapper.deleteTargetIdRelation(map.get("rel_id").toString(), map.get("s_id").toString(), targetId);
            }
        }
    }

    @Override
    public void deleteTargetValue(String targetId) {
        List<Map<String, Object>> list = knowMapper.selectTargetValueData(targetId);
        if (CollectionUtil.isNotEmpty(list)) {
            for (Map<String, Object> map : list) {
                //删除价值分析与此目标关联的数据
                systemValue(targetId, map.get("rel_id").toString(), null, null, 0.0, 0.0);
                systemsValue(targetId, map.get("rel_id").toString(), map.get("s_id").toString(), null, null, 0.0, 0.0);
                knowMapper.deleteTargetIdRelation(map.get("rel_id").toString(), map.get("s_id").toString(), targetId);
            }
        }
        //删除系统与体系关联的目标
        targetMapper.deleteSystemRelation(targetId);
        targetMapper.deleteSystemsRelation(targetId);
        targetMapper.deleteSystemsShip(targetId);
    }

    @Override
    public void deleteSubTargetValue(String sudId) {
        List<Map<String, Object>> list = knowMapper.selectSubValueData(sudId);
        if (CollectionUtil.isNotEmpty(list)) {
            for (Map<String, Object> map : list) {
                //删除价值分析与此子目标关联的数据
                targetValue(sudId, map.get("target_id").toString(), null, 0.0, 0.0);
                systemValue(sudId, map.get("rel_id").toString(), map.get("target_id").toString(), null, 0.0, 0.0);
                systemsValue(sudId, map.get("rel_id").toString(), map.get("s_id").toString(), map.get("target_id").toString(), null, 0.0, 0.0);
                knowMapper.deleteSubIdRelation(map.get("rel_id").toString(), map.get("s_id").toString(), map.get("target_id").toString(), sudId);
            }
        }
    }

    @Override
    public void deleteKnowValue(String knowId) {
        List<Map<String, Object>> list = knowMapper.selectKnowValueData(knowId);
        if (CollectionUtil.isNotEmpty(list)) {
            for (Map<String, Object> map : list) {
                //删除价值分析与此子目标关联的数据
                systemValue(map.get("sub_id").toString(), map.get("rel_id").toString(), map.get("target_id").toString(), knowId, 0.0, 0.0);
                systemsValue(map.get("sub_id").toString(), map.get("rel_id").toString(), map.get("s_id").toString(), map.get("target_id").toString(), knowId, 0.0, 0.0);
            }
        }
    }

    @Override
    public void updateKnowIndexAndRemark(String name, String replace, int type, int status, String typeId) {
//        if (status == 1 && type == 1) {
//            List<KnowData> knowData = knowMapper.selectKnowIndexAndRemark(name, type, status);
//            if (CollectionUtil.isNotEmpty(knowData)) {
//                for (KnowData knowDatum : knowData) {
//                    String indes = knowDatum.getIndexData();
//                    knowDatum.setIndexData(indes.replaceAll(name, replace));
//                    String remark = knowDatum.getRemark();
//                    knowDatum.setRemark(remark.replaceAll(name, replace));
//                    knowMapper.updateKnowIndexAndRemark(knowDatum);
//                }
//            }
//            List<KnowData> knowDatas = knowMapper.selectSystemKnowIndexAndRemark(name, type);
//            if (CollectionUtil.isNotEmpty(knowDatas)) {
//                for (KnowData knowDatum : knowDatas) {
//                    String indes = knowDatum.getIndexData();
//                    knowDatum.setIndexData(indes.replaceAll(name, replace));
//                    String remark = knowDatum.getRemark();
//                    knowDatum.setRemark(remark.replaceAll(name, replace));
//                    knowMapper.updateSystemKnowIndexAndRemark(knowDatum);
//                }
//            }
//        } else if (type == 2) {
//            List<KnowData> knowData = knowMapper.selectKnowIndexAndRemarkByMainSpecial(typeId);
//            if (CollectionUtil.isNotEmpty(knowData)) {
//                for (KnowData knowDatum : knowData) {
//                    String indes = knowDatum.getIndexData();
//                    knowDatum.setIndexData(indes.replaceAll(name, replace));
//                    String remark = knowDatum.getRemark();
//                    knowDatum.setRemark(remark.replaceAll(name, replace));
//                    knowMapper.updateKnowIndexAndRemark(knowDatum);
//                }
//            }
//            if (status == 1) {
//                List<KnowData> knowDataList = knowMapper.selectSystemKnowIndexAndRemarkByMainSpecial(typeId);
//                if (CollectionUtil.isNotEmpty(knowDataList)) {
//                    for (KnowData knowDatum : knowDataList) {
//                        String indes = knowDatum.getIndexData();
//                        knowDatum.setIndexData(indes.replaceAll(name, replace));
//                        String remark = knowDatum.getRemark();
//                        knowDatum.setRemark(remark.replaceAll(name, replace));
//                        knowMapper.updateSystemKnowIndexAndRemark(knowDatum);
//                    }
//                }
//            }
//        } else if (status == 2 && type == 1) {
//            List<KnowData> knowData = knowMapper.selectKnowIndexAndRemark(name, type, status);
//            if (CollectionUtil.isNotEmpty(knowData)) {
//                for (KnowData knowDatum : knowData) {
//                    String indes = knowDatum.getIndexData();
//                    knowDatum.setIndexData(indes.replaceAll(name, replace));
//                    String remark = knowDatum.getRemark();
//                    knowDatum.setRemark(remark.replaceAll(name, replace));
//                    knowMapper.updateKnowIndexAndRemark(knowDatum);
//                }
//            }
//        }
    }

    @Override
    public Result selectSysType(int type) {
        List<SystemType> types = systemTypeMapper.selectSystemTypeList(type);
        List<Map<String, Object>> resultList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(types)) {
            Map<String, Object> map = null;
            for (SystemType systemType : types) {
                map = new HashMap<>();
                if (type != 1) {
                    map.put("value", systemType.getTypeId());
                } else {
                    map.put("value", systemType.getTypeName());
                }
                map.put("label", systemType.getId());
                resultList.add(map);
            }
        }
        return ResultUtil.success(resultList);
    }

    /**
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @author zhangxuan
     * @Description TODO 主目标分析
     * @Date 9:45 2022/2/25
     * @Param [targetId, sign]
     **/
    private Map<String, Object> mainTargetAnalyze(TargetData only, int type, boolean map) {
        Map<String, Object> mainMap = new HashMap<>();
        mainMap.put("targetName", only.getTargetName());
        mainMap.put("targetId", only.getTargetId());
        String typeName = targetTypeMapper.getTypeName(only.getTargetClassify());
        mainMap.put("targetType", typeName);
        String icon = targetTypeMapper.getSign(MyUtil.classToString(only.getTargetClassify()));
        mainMap.put("icon", StringUtils.isNotBlank(icon) ? this.keyWordSystem.getSERVER_URL() + "/sign/" + icon : null);
        try {
            Map<String, Object> targetData = repo.selectTargetData(keyWordSystem.getFILE_URL() + only.getSqliteUrl(), Arrays.asList("desicribe"));
            mainMap.put("remark", targetData.get("desicribe"));
        } catch (SQLException sqlException) {
            mainMap.put("remark", "");
        }
        //目标图片地址
        mainMap.put("url", StringUtils.isNotBlank(only.getIcon()) ? this.keyWordSystem.getSERVER_URL() + only.getIcon() : this.keyWordSystem.getSERVER_URL() + "/default/default.jpg");
        //封装地图参数
        if (map) {
            List<String> data = new ArrayList<>();
            data.add("position");
            data.add("area");
            data.add("plotinfoobj");
            Map<String, Object> mainData = new HashMap<>();
            try {
                mainData = repo.selectTargetData(this.keyWordSystem.getFILE_URL() + only.getSqliteUrl(), data);
            } catch (SQLException sqlException) {
                sqlException.printStackTrace();
            }
            mainMap.put("position", null != mainData.get("position") ? FileElseUtil.getStringTransitionList(mainData.get("position").toString()) : "[]");
            mainMap.put("area", mainData.get("area"));
            mainMap.put("plotinfoobj", mainData.get("plotinfoobj"));
            SystemPosition position = systemPositionMapper.getPositionById(only.getTargetId());
            if (null != position) {
                mainMap.put("height", StringUtils.isNotBlank(position.getHeight()) ? position.getHeight() : null);
                mainMap.put("viewDistances", StringUtils.isNotBlank(position.getViewDistances()) ? FileElseUtil.getStringTransitionList(position.getViewDistances()) : new ArrayList<>());
            } else {
                mainMap.put("height", null);
                mainMap.put("viewDistances", new ArrayList<>());
            }
        }
        //前端显示封装
        ArrayList<ArrayList<Object>> infolist = new ArrayList<>();
        List<KnowData> knowDatas = new ArrayList<>();
        if (type == 0 || type == 1) {
            List<KnowData> knows = knowMapper.selectKnowTargetList(only.getTargetClassify(), "结构分析");
            if (CollectionUtil.isNotEmpty(knows)) {
                knowDatas.addAll(knows);
            }
            knows = knowMapper.selectKnowTargetList(only.getTargetClassify(), "功能分析");
            if (CollectionUtil.isNotEmpty(knows)) {
                knowDatas.addAll(knows);
            }
        } else {
            knowDatas = knowMapper.selectKnowTargetList(only.getTargetClassify(), "特性分析");
        }
        if (CollectionUtil.isNotEmpty(knowDatas)) {
            for (KnowData knowData : knowDatas) {
                ArrayList<Object> subData = new ArrayList<>();
                //知识名称
                String name = "";
                //描述
                String remark = "";
                //结果
                String effect = "";
                //指标选择判断
                boolean mainJuage = false;
                //指标描述判断
                boolean mainRemarkJuage = true;
                //目标指数查询
                Map<String, Object> mainIndexMap = null;
                //指标列表
                List<String> indexList = new ArrayList<>();
                name = knowData.getName();
                remark = knowData.getRemark();
                if (StringUtils.isNotBlank(knowData.getIndexData())) {
                    mainJuage = true;
                    indexList = FileElseUtil.getStringTransitionList(knowData.getIndexData());
                }
                if (mainJuage) {
                    try {
                        if (knowData.getType().equals("1")) {
                            mainIndexMap = repo.selectTargetData(this.keyWordSystem.getFILE_URL() + only.getSqliteUrl(), indexList);
                        } else {
                            mainIndexMap = repo.selectTargetElseData(this.keyWordSystem.getFILE_URL() + only.getSqliteUrl(), indexList);
                        }
                        if (CollectionUtil.isNotEmpty(mainIndexMap) && StringUtils.isNotBlank(remark)) {
                            for (String s : mainIndexMap.keySet()) {
                                Object o = mainIndexMap.get(s);
                                if (null == o) {
                                    mainRemarkJuage = false;
                                }
                                remark = remark.replace("{" + s + "}", null != o ? o.toString() : "");
                            }
                        }
                    } catch (SQLException e) {
                        log.info("查询指标异常", e);
                    }
                }
                if (mainJuage && mainRemarkJuage && CollectionUtil.isNotEmpty(mainIndexMap)) {
                    List<KnowRelationData> effectList = knowMapper.selectKnowRelationList(knowData.getId());
                    if (CollectionUtil.isNotEmpty(effectList)) {
                        //结果判断
                        boolean effectJuage = false;
                        for (KnowRelationData relationData : effectList) {
                            for (int i = 0; i < indexList.size(); i++) {
                                double a = FileElseUtil.getStringTransitionDouble(mainIndexMap.get(indexList.get(i)).toString());
                                List indexL = FileElseUtil.getStringTransitionList(relationData.getIndexOne());
                                if (a != 0D && CollectionUtil.isNotEmpty(indexL)) {
                                    if (a >= Double.parseDouble(indexL.get(0).toString()) && a <= Double.parseDouble(indexL.get(1).toString())) {
                                        effectJuage = true;
                                    } else {
                                        effectJuage = false;
                                        break;
                                    }
                                }
                            }
                            if (effectJuage) {
                                effect = relationData.getEffect();
                                remark = remark.replace("{result}", effect);
                                break;
                            }
                        }
                    }
                }
                subData.add(name);
                subData.add(remark);
                infolist.add(subData);
            }
        }
        mainMap.put("infolist", infolist);
        return mainMap;
    }

    /**
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @author zhangxuan
     * @Description TODO 主系统分析
     * @Date 9:45 2022/2/25
     * @Param [targetId, sign]
     **/
    private Map<String, Object> mainSystemAnalyze(SystemMaster only, int type) {
        Map<String, Object> mainMap = new HashMap<>();
        //目标图片地址
        mainMap.put("url", StringUtils.isNotBlank(only.getIcon()) ? this.keyWordSystem.getSERVER_URL() + only.getIcon() : this.keyWordSystem.getSERVER_URL() + "/default/default.jpg");
        mainMap.put("systemName", only.getSystemName());
        mainMap.put("remark", only.getRemark());
        SystemPosition positionById = systemPositionMapper.getPositionById(only.getSId());
        if (ObjectUtil.isNotEmpty(positionById)) {
            mainMap.put("position", FileElseUtil.getStringTransitionList(positionById.getPositions()));
            mainMap.put("height", StringUtils.isNotBlank(positionById.getHeight()) ? positionById.getHeight() : null);
            mainMap.put("viewDistances", FileElseUtil.getStringTransitionList(positionById.getViewDistances()));
        } else {
            mainMap.put("position", new ArrayList<>());
            mainMap.put("height", null);
            mainMap.put("viewDistances", new ArrayList<>());
        }
        //前端显示封装
        ArrayList<ArrayList<Object>> infolist = new ArrayList<>();
        String sysType = "0";
        if (StringUtils.isNotBlank(only.getUserSign()) && only.getUserSign().split("&&").length > 1) {
            sysType = only.getUserSign().split("&&")[1];
        }
        List<KnowData> knowDatas = new ArrayList<>();
        if (type == 0 || type == 1) {
            List<KnowData> knows = knowMapper.selectKnowSystemOne(sysType, "结构分析");
            if (CollectionUtil.isNotEmpty(knows)) {
                knowDatas.addAll(knows);
            }
            knows = knowMapper.selectKnowSystemOne(sysType, "功能分析");
            if (CollectionUtil.isNotEmpty(knows)) {
                knowDatas.addAll(knows);
            }
        } else {
            knowDatas = knowMapper.selectKnowSystemOne(sysType, "特性分析");
        }
        if (CollectionUtil.isNotEmpty(knowDatas)) {
            for (KnowData knowData : knowDatas) {
                ArrayList<Object> subData = new ArrayList<>();
                subData.add(knowData.getName());
                //指标分析
                boolean mainJuage = false;
                List<String> indexList = null;
                if (StringUtils.isNotBlank(knowData.getIndexData())) {
                    mainJuage = true;
                    indexList = FileElseUtil.getStringTransitionList(knowData.getIndexData());
                }
                if (mainJuage) {
                    try {
                        Map<String, Double> value = new HashMap<>();
                        List<Map<String, Object>> list = systemRelationMapper.selectSystemRelationTargetIdAndName(only.getSId());
                        if (CollectionUtil.isNotEmpty(list)) {
                            for (Map<String, Object> map : list) {
                                TargetData targetData = targetMapper.findTargetOnly(map.get("targetId").toString());
                                if (null != targetData) {
                                    List<String> indexs = new ArrayList<>();
                                    if (CollectionUtil.isNotEmpty(indexList)) {
                                        indexs.addAll(indexList);
                                    } else {
                                        continue;
                                    }
                                    Map<String, Object> mainIndexMap = null;
                                    if (knowData.getType().equals("1")) {
                                        mainIndexMap = repo.selectTargetData(this.keyWordSystem.getFILE_URL() + targetData.getSqliteUrl(), indexs);
                                    } else {
                                        mainIndexMap = repo.selectTargetElseData(this.keyWordSystem.getFILE_URL() + targetData.getSqliteUrl(), indexs);
                                    }
                                    if (CollectionUtil.isNotEmpty(mainIndexMap) && StringUtils.isNotBlank(knowData.getRemark())) {
                                        for (String s : mainIndexMap.keySet()) {
                                            Object o = mainIndexMap.get(s);
                                            if (null != value.get(s) && StringUtils.isNotBlank(value.get(s).toString())) {
                                                value.put(s, Double.valueOf(value.get(s).toString()) + FileElseUtil.getStringTransitionDouble(null != o ? o.toString() : ""));
                                            } else {
                                                value.put(s, null != o ? FileElseUtil.getStringTransitionDouble(o.toString()) : 0);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (CollectionUtil.isNotEmpty(value)) {
                            for (String s : value.keySet()) {
                                knowData.setRemark(knowData.getRemark().replace("{" + s + "}", value.get(s).toString()));
                            }
                            subData.add(knowData.getRemark());
                        }
                    } catch (Exception e) {
                        log.info("查询指标异常", e);
                    }
                } else {
                    subData.add(knowData.getRemark());
                }
                //指标分析end
                infolist.add(subData);
            }
        }
        mainMap.put("infolist", infolist);
        return mainMap;
    }

    /**
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @author zhangxuan
     * @Description TODO 主体系分析
     * @Date 9:45 2022/2/25
     * @Param [targetId, sign]
     **/
    private Map<String, Object> mainSystemsAnalyze(SystemsMaster only, int type) {
        Map<String, Object> mainMap = new HashMap<>();
        //目标图片地址
        mainMap.put("url", StringUtils.isNotBlank(only.getIcon()) ? this.keyWordSystem.getSERVER_URL() + only.getIcon() : this.keyWordSystem.getSERVER_URL() + "/default/default.jpg");
        mainMap.put("systemsName", only.getSystemsName());
        mainMap.put("remark", only.getRemark());
        SystemPosition positionById = systemPositionMapper.getPositionById(only.getSysId());
        if (ObjectUtil.isNotEmpty(positionById)) {
            mainMap.put("position", FileElseUtil.getStringTransitionList(positionById.getPositions()));
            mainMap.put("height", StringUtils.isNotBlank(positionById.getHeight()) ? positionById.getHeight() : null);
            mainMap.put("viewDistances", FileElseUtil.getStringTransitionList(positionById.getViewDistances()));
        } else {
            mainMap.put("position", new ArrayList<>());
            mainMap.put("height", null);
            mainMap.put("viewDistances", new ArrayList<>());
        }
        //前端显示封装
        ArrayList<ArrayList<Object>> infolist = new ArrayList<>();
        String systemType = "0";
        if (StringUtils.isNotBlank(only.getUserSign()) && only.getUserSign().split("&&").length > 1) {
            systemType = only.getUserSign().split("&&")[1];
        }
        List<KnowData> knowDatas = new ArrayList<>();
        if (type == 0 || type == 1) {
            List<KnowData> knows = knowMapper.selectKnowSystemsOne(systemType, "结构分析");
            if (CollectionUtil.isNotEmpty(knows)) {
                knowDatas.addAll(knows);
            }
            knows = knowMapper.selectKnowSystemsOne(systemType, "功能分析");
            if (CollectionUtil.isNotEmpty(knows)) {
                knowDatas.addAll(knows);
            }
        } else {
            knowDatas = knowMapper.selectKnowSystemsOne(systemType, "特性分析");
        }
        if (CollectionUtil.isNotEmpty(knowDatas)) {
            for (KnowData knowData : knowDatas) {
                ArrayList<Object> subData = new ArrayList<>();
                subData.add(knowData.getName());
                subData.add(knowData.getRemark());
                infolist.add(subData);
            }
        }
        mainMap.put("infolist", infolist);
        return mainMap;
    }

    /**
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @author zhangxuan
     * @Description TODO 主系统目标分析
     * @Date 9:45 2022/2/25
     * @Param [targetId, sign]
     **/
    private List<Map<String, Object>> mainSystemTargetAnalyze(String sId, int type, boolean map) {
        List<Map<String, Object>> resultList = new ArrayList<>();
        List<TargetData> targetList = systemMasterMapper.selectSystenRelationTargetList(sId);
        if (CollectionUtil.isNotEmpty(targetList)) {
            for (TargetData only : targetList) {
                resultList.add(mainTargetAnalyze(only, type, map));
            }
        }
        if ((type == 3 || type == 4) && CollectionUtil.isNotEmpty(resultList)) {
            String targetId = "";
            Map<String, Object> maxTargetId = knowMapper.selectValueMaxTargetId(sId);
            if (null != maxTargetId) {
                targetId = maxTargetId.get("target_id").toString();
            }
            for (Map<String, Object> stringObjectMap : resultList) {
                stringObjectMap.remove("infolist");
                if (stringObjectMap.get("targetId").toString().equals(targetId)) {
                    stringObjectMap.put("crucial", true);
                } else {
                    stringObjectMap.put("crucial", false);
                }
            }
        }
        return resultList;
    }

    /**
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @author zhangxuan
     * @Description TODO 主体系系统分析
     * @Date 9:45 2022/2/25
     * @Param [targetId, sign]
     **/
    private List<Map<String, Object>> mainSystemsSystemAnalyze(SystemsMaster systemsMaster, int type) {
        List<Map<String, Object>> resultList = new ArrayList<>();
        if (StringUtils.isNotBlank(systemsMaster.getIncludeType())) {
            String[] split = systemsMaster.getIncludeType().split(",");
            for (String sId : split) {
                SystemMaster systemMaster = systemMasterMapper.selectSystemOnly(sId);
                if (null != systemMaster) {
                    resultList.add(mainSystemAnalyze(systemMaster, type));
                }
            }
        }
        return resultList;
    }

    private List<Map<String, Object>> mainSystemsSystemAnalyzeMap(SystemsMaster systemsMaster, int type) {
        List<Map<String, Object>> resultList = new ArrayList<>();
        List<String> list = new ArrayList<>();
        if (StringUtils.isNotBlank(systemsMaster.getIncludeType())) {
            String[] split = systemsMaster.getIncludeType().split(",");
            list = Arrays.asList(split);
        } else {
            list.add("");
        }
        //查询系统包含的目标
        List<String> targetList = systemsMasterMapper.selectSystemsHavaTargetId(systemsMaster.getSysId(), list);
        if (CollectionUtil.isNotEmpty(targetList)) {
            for (String s : targetList) {
                TargetData only = targetMapper.findTargetOnly(s);
                if (null != only) {
                    resultList.add(mainTargetAnalyze(only, type, true));
                }
            }
        }
        if ((type == 3 || type == 4) && CollectionUtil.isNotEmpty(resultList)) {
            String targetId = "";
            Map<String, Object> maxTargetId = knowMapper.selectValueMaxTargetId(systemsMaster.getSysId());
            if (null != maxTargetId) {
                targetId = maxTargetId.get("target_id").toString();
            }
            for (Map<String, Object> stringObjectMap : resultList) {
                stringObjectMap.remove("infolist");
                if (stringObjectMap.get("targetId").toString().equals(targetId)) {
                    stringObjectMap.put("crucial", true);
                } else {
                    stringObjectMap.put("crucial", false);
                }
            }
        }
        return resultList;
    }

    private List<Map<String, Object>> weaponAnalyze(String targetId) {
        List<Map<String, Object>> resultList = new ArrayList<>();
        List<WeaponRelation> weaponRelations = weaponHouseMapper.selectWeaponTargetRelationNameByTargetId(targetId);
        if (CollectionUtil.isNotEmpty(weaponRelations)) {
            Map<String, Object> subMap = null;
            for (WeaponRelation weaponRelation : weaponRelations) {
                subMap = new HashMap<>();
                //目标图片地址
                subMap.put("targetName", weaponRelation.getWeaponId());
                subMap.put("targetType", weaponRelation.getTypeId());
                subMap.put("url", StringUtils.isNotBlank(weaponRelation.getIcon()) ? this.keyWordSystem.getSERVER_URL() + weaponRelation.getIcon() : this.keyWordSystem.getSERVER_URL() + "/default/default.jpg");
                subMap.put("subId", weaponRelation.getId());
                subMap.put("position", FileElseUtil.getStringTransitionList(weaponRelation.getPosition()));
                subMap.put("area", "0㎡");
                subMap.put("plotinfoobj", new ArrayList<>());
                SystemPosition position = systemPositionMapper.getPositionById(weaponRelation.getId());
                if (null != position) {
                    subMap.put("height", StringUtils.isNotBlank(position.getHeight()) ? position.getHeight() : null);
                    subMap.put("viewDistances", StringUtils.isNotBlank(position.getViewDistances()) ? FileElseUtil.getStringTransitionList(position.getViewDistances()) : new ArrayList<>());
                } else {
                    subMap.put("height", null);
                    subMap.put("viewDistances", new ArrayList<>());
                }
                subMap.put("infolist", new ArrayList<>());
                resultList.add(subMap);
            }
        }
        return resultList;
    }

    private List<Map<String, Object>> subAnalyze(String sqliteUrl, int type, boolean maps) {
        List<Map<String, Object>> resultList = new ArrayList<>();
        List<String> subData = new ArrayList<>();
        subData.add("targetName");
        subData.add("icon");
        subData.add("targetClassify");
        if (maps) {
            subData.add("position");
            subData.add("area");
            subData.add("plotinfoobj");
        }
        try {
            List<Map<String, Object>> subList = repo.selectTargetSubData(sqliteUrl, subData);
            if (CollectionUtil.isNotEmpty(subList)) {
                Map<String, Object> subMap = null;
                for (Map<String, Object> map : subList) {
                    subMap = new HashMap<>();
                    //目标图片地址
                    subMap.put("targetName", map.get("targetName"));
                    String typeName = targetTypeMapper.getTypeName(null != map.get("targetClassify") ? map.get("targetClassify").toString() : "");
                    subMap.put("targetType", typeName);
                    subMap.put("url", null != map.get("icon") ? this.keyWordSystem.getSERVER_URL() + map.get("icon").toString() : this.keyWordSystem.getSERVER_URL() + "/default/default.jpg");
                    if (null != map.get("targetClassify")) {
                        String icon = targetTypeMapper.getSign(MyUtil.classToString(map.get("targetClassify").toString()));
                        map.put("icon", StringUtils.isNotBlank(icon) ? this.keyWordSystem.getSERVER_URL() + "/sign/" + icon : null);
                    } else {
                        map.put("icon", null);
                    }
                    if (maps) {
                        subMap.put("subId", map.get("subId").toString());
                        subMap.put("position", null != map.get("position") ? FileElseUtil.getStringTransitionList(map.get("position").toString()) : "[]");
                        subMap.put("area", map.get("area"));
                        subMap.put("plotinfoobj", map.get("plotinfoobj"));
                        SystemPosition position = systemPositionMapper.getPositionById(subMap.get("subId").toString());
                        if (null != position) {
                            subMap.put("height", StringUtils.isNotBlank(position.getHeight()) ? position.getHeight() : null);
                            subMap.put("viewDistances", StringUtils.isNotBlank(position.getViewDistances()) ? FileElseUtil.getStringTransitionList(position.getViewDistances()) : new ArrayList<>());
                        } else {
                            subMap.put("height", null);
                            subMap.put("viewDistances", new ArrayList<>());
                        }
                    }
                    //前端显示封装
                    ArrayList<ArrayList<Object>> infolist = new ArrayList<>();
                    //名称
                    List<KnowData> knowDatas = new ArrayList<>();
                    if (type == 0 || type == 1) {
                        List<KnowData> knows = knowMapper.selectKnowTargetList(map.get("targetClassify").toString(), "结构分析");
                        if (CollectionUtil.isNotEmpty(knows)) {
                            knowDatas.addAll(knows);
                        }
                        knows = knowMapper.selectKnowTargetList(map.get("targetClassify").toString(), "功能分析");
                        if (CollectionUtil.isNotEmpty(knows)) {
                            knowDatas.addAll(knows);
                        }
                    } else {
                        knowDatas = knowMapper.selectKnowTargetList(map.get("targetClassify").toString(), "特性分析");
                    }
                    if (CollectionUtil.isNotEmpty(knowDatas)) {
                        for (KnowData knowData : knowDatas) {
                            ArrayList<Object> datas = new ArrayList<>();
                            //知识名称
                            String name = "";
                            //描述
                            String remark = "";
                            //结果
                            String effect = "";
                            //指标选择判断
                            boolean mainJuage = false;
                            //指标描述判断
                            boolean mainRemarkJuage = true;
                            //目标指数查询
                            Map<String, Object> mainIndexMap = null;
                            //指标列表
                            List<String> indexList = new ArrayList<>();
                            if (null != knowData) {
                                name = knowData.getName();
                                remark = knowData.getRemark();
                                if (StringUtils.isNotBlank(knowData.getIndexData())) {
                                    mainJuage = true;
                                    indexList = FileElseUtil.getStringTransitionList(knowData.getIndexData());
                                }
                                if (mainJuage) {
                                    try {
                                        if (knowData.getType().equals("1")) {
                                            mainIndexMap = repo.selectTargetSub(sqliteUrl, map.get("subId").toString());
                                        } else {
                                            mainIndexMap = repo.selectTargetSubElse(sqliteUrl, map.get("subId").toString());
                                        }
                                        if (CollectionUtil.isNotEmpty(mainIndexMap) && StringUtils.isNotBlank(remark)) {
                                            for (String s : mainIndexMap.keySet()) {
                                                Object o = mainIndexMap.get(s);
                                                if (null == o) {
                                                    mainRemarkJuage = false;
                                                }
                                                remark = remark.replace("{" + s + "}", null != o ? o.toString() : "");
                                            }
                                        }
                                    } catch (SQLException e) {
                                        log.info("查询指标异常", e);
                                    }
                                }
                                if (mainJuage && mainRemarkJuage && CollectionUtil.isNotEmpty(mainIndexMap)) {
                                    List<KnowRelationData> effectList = knowMapper.selectKnowRelationList(knowData.getId());
                                    if (CollectionUtil.isNotEmpty(effectList)) {
                                        //结果判断
                                        boolean effectJuage = false;
                                        for (KnowRelationData relationData : effectList) {
                                            for (int i = 0; i < indexList.size(); i++) {
                                                if (null != mainIndexMap.get(indexList.get(i))) {
                                                    double a = FileElseUtil.getStringTransitionDouble(mainIndexMap.get(indexList.get(i)).toString());
                                                    List indexL = FileElseUtil.getStringTransitionList(relationData.getIndexOne());
                                                    if (a != 0D && CollectionUtil.isNotEmpty(indexL)) {
                                                        if (a >= Double.parseDouble(indexL.get(0).toString()) && a <= Double.parseDouble(indexL.get(1).toString())) {
                                                            effectJuage = true;
                                                        } else {
                                                            effectJuage = false;
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                            if (effectJuage) {
                                                effect = relationData.getEffect();
                                                remark = remark.replace("{result}", effect);
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            datas.add(name);
                            datas.add(remark);
                            infolist.add(datas);
                        }
                    }
                    subMap.put("infolist", infolist);
                    resultList.add(subMap);
                }
            }
        } catch (SQLException e) {
            log.error("子目标分析异常", e);
        }
        return resultList;
    }

    private int systemValue(String id, String sId, String targetId, String knowId, Double score, Double weight) {
        if (StringUtils.isNotBlank(targetId) && StringUtils.isNotBlank(sId) && StringUtils.isNotBlank(knowId)) {
            //查询单挑打分项
            ValueData knowData = knowMapper.selectValueOnly(sId, "001", targetId, id, knowId);
            double oldGoal = 0D;
            double value = new BigDecimal(score * weight).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue();
            if (null == knowData) {
                knowData = new ValueData();
                knowData.setId(snow.nextId() + "");
                knowData.setRelId(sId);
                knowData.setSId("001");
                knowData.setTargetId(targetId);
                knowData.setSubId(id);
                knowData.setKnowId(knowId);
                knowData.setScore(score);
                knowData.setWeight(weight);
                knowData.setGoal(value);
            } else {
                oldGoal = knowData.getGoal();
                knowData.setScore(score);
                knowData.setWeight(weight);
                knowData.setGoal(value);
            }
            double oldSubGoal = 0D;
            //查询子目标单条
            ValueData subData = knowMapper.selectValueOnly(sId, "001", targetId, id, null);
            if (null == subData) {
                subData = new ValueData();
                subData.setId(snow.nextId() + "");
                subData.setRelId(sId);
                subData.setSId("001");
                subData.setTargetId(targetId);
                subData.setSubId(id);
                subData.setScore(value);
                subData.setWeight(0D);
                subData.setGoal(0D);
            } else {
                oldSubGoal = subData.getGoal();
                subData.setScore(new BigDecimal(subData.getScore() - oldGoal + value).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
                subData.setGoal(new BigDecimal(subData.getScore() * subData.getWeight()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
            }
            //查询目标单条
            ValueData targetData = knowMapper.selectValueOnly(sId, "001", targetId, null, null);
            if (null == targetData) {
                targetData = new ValueData();
                targetData.setId(snow.nextId() + "");
                targetData.setRelId(sId);
                targetData.setSId("001");
                targetData.setTargetId(targetId);
                targetData.setScore(subData.getGoal());
                targetData.setWeight(0D);
                targetData.setGoal(0D);
            } else {
                targetData.setScore(new BigDecimal(targetData.getScore() - oldSubGoal + subData.getGoal()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
                targetData.setGoal(new BigDecimal(targetData.getScore() * targetData.getWeight()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
            }
            knowMapper.addValue(targetData);
            knowMapper.addValue(subData);
            knowMapper.addValue(knowData);
        } else if (StringUtils.isNotBlank(targetId) && StringUtils.isNotBlank(sId)) {
            //查询子目标单条
            ValueData subData = knowMapper.selectValueOnly(sId, "001", targetId, id, null);
            double oldGoal = 0D;
            if (null == subData) {
                subData = new ValueData();
                subData.setId(snow.nextId() + "");
                subData.setRelId(sId);
                subData.setSId("001");
                subData.setTargetId(targetId);
                subData.setSubId(id);
                subData.setScore(0D);
                subData.setWeight(weight);
                subData.setGoal(0D);
            } else {
                oldGoal = subData.getGoal();
                subData.setWeight(weight);
                subData.setGoal(new BigDecimal(subData.getScore() * weight).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
            }
            double targetGoal = 0D;
            //查询目标单条
            ValueData targetData = knowMapper.selectValueOnly(sId, "001", targetId, null, null);
            if (null == targetData) {
                targetData = new ValueData();
                targetData.setId(snow.nextId() + "");
                targetData.setRelId(sId);
                targetData.setSId("001");
                targetData.setTargetId(targetId);
                targetData.setScore(subData.getGoal());
                targetData.setWeight(0D);
                targetData.setGoal(0D);
            } else {
                targetGoal = targetData.getGoal();
                targetData.setScore(new BigDecimal(targetData.getScore() - oldGoal + subData.getGoal()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
                targetData.setGoal(new BigDecimal(targetData.getScore() * targetData.getWeight()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
            }
            knowMapper.addValue(targetData);
            knowMapper.addValue(subData);
        } else if (StringUtils.isNotBlank(sId)) {
            double goal = 0D;
            //查询目标单条
            ValueData targetData = knowMapper.selectValueOnly(sId, "001", id, null, null);
            if (null == targetData) {
                targetData = new ValueData();
                targetData.setId(snow.nextId() + "");
                targetData.setRelId(sId);
                targetData.setSId("001");
                targetData.setTargetId(id);
                targetData.setScore(0D);
                targetData.setWeight(weight);
                targetData.setGoal(0D);
            } else {
                goal = targetData.getGoal();
                targetData.setWeight(weight);
                targetData.setGoal(new BigDecimal(targetData.getScore() * targetData.getWeight()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
            }
            knowMapper.addValue(targetData);
        } else {
            return 0;
        }
        return 1;
    }

    private int targetValue(String id, String targetId, String knowId, Double score, Double weight) {
        if (StringUtils.isNotBlank(targetId) && StringUtils.isNotBlank(knowId)) {
            //查询单挑打分项
            ValueData knowData = knowMapper.selectValueOnly("003", "003", targetId, id, knowId);
            double oldGoal = 0D;
            double value = new BigDecimal(score * weight).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue();
            if (null == knowData) {
                knowData = new ValueData();
                knowData.setId(snow.nextId() + "");
                knowData.setRelId("003");
                knowData.setSId("003");
                knowData.setTargetId(targetId);
                knowData.setSubId(id);
                knowData.setKnowId(knowId);
                knowData.setScore(score);
                knowData.setWeight(weight);
                knowData.setGoal(value);
            } else {
                oldGoal = knowData.getGoal();
                knowData.setScore(score);
                knowData.setWeight(weight);
                knowData.setGoal(value);
            }
            double oldSubGoal = 0D;
            //查询子目标单条
            ValueData subData = knowMapper.selectValueOnly("003", "003", targetId, id, null);
            if (null == subData) {
                subData = new ValueData();
                subData.setId(snow.nextId() + "");
                subData.setRelId("003");
                subData.setSId("003");
                subData.setTargetId(targetId);
                subData.setSubId(id);
                subData.setScore(value);
                subData.setWeight(0D);
                subData.setGoal(0D);
            } else {
                oldSubGoal = subData.getGoal();
                subData.setScore(new BigDecimal(subData.getScore() - oldGoal + value).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
                subData.setGoal(new BigDecimal(subData.getScore() * subData.getWeight()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
            }
            //查询目标单条
            ValueData targetData = knowMapper.selectValueOnly("003", "003", targetId, null, null);
            if (null == targetData) {
                targetData = new ValueData();
                targetData.setId(snow.nextId() + "");
                targetData.setRelId("003");
                targetData.setSId("003");
                targetData.setTargetId(targetId);
                targetData.setScore(subData.getGoal());
                targetData.setWeight(0D);
                targetData.setGoal(0D);
            } else {
                targetData.setScore(new BigDecimal(targetData.getScore() - oldSubGoal + subData.getGoal()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
                targetData.setGoal(new BigDecimal(targetData.getScore() * targetData.getWeight()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
            }
            knowMapper.addValue(targetData);
            knowMapper.addValue(subData);
            knowMapper.addValue(knowData);
        } else if (StringUtils.isNotBlank(targetId)) {
            //查询子目标单条
            ValueData subData = knowMapper.selectValueOnly("003", "003", targetId, id, null);
            double oldGoal = 0D;
            if (null == subData) {
                subData = new ValueData();
                subData.setId(snow.nextId() + "");
                subData.setRelId("003");
                subData.setSId("003");
                subData.setTargetId(targetId);
                subData.setSubId(id);
                subData.setScore(0D);
                subData.setWeight(weight);
                subData.setGoal(0D);
            } else {
                oldGoal = subData.getGoal();
                subData.setWeight(weight);
                subData.setGoal(new BigDecimal(subData.getScore() * weight).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
            }
            double targetGoal = 0D;
            //查询目标单条
            ValueData targetData = knowMapper.selectValueOnly("003", "003", targetId, null, null);
            if (null == targetData) {
                targetData = new ValueData();
                targetData.setId(snow.nextId() + "");
                targetData.setRelId("003");
                targetData.setSId("003");
                targetData.setTargetId(targetId);
                targetData.setScore(subData.getGoal());
                targetData.setWeight(0D);
                targetData.setGoal(0D);
            } else {
                targetGoal = targetData.getGoal();
                targetData.setScore(new BigDecimal(targetData.getScore() - oldGoal + subData.getGoal()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
                targetData.setGoal(new BigDecimal(targetData.getScore() * targetData.getWeight()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
            }
            knowMapper.addValue(targetData);
            knowMapper.addValue(subData);
        } else {
            return 0;
        }
        return 1;
    }

    /**
     * 系统价值计算
     *
     * @param id
     * @param sysId
     * @param sId
     * @param targetId
     * @param knowId
     * @param score
     * @param weight
     * @return
     */
    private int systemsValue(String id, String sysId, String sId, String targetId, String knowId, Double score, Double weight) {
        if (StringUtils.isNotBlank(targetId) && StringUtils.isNotBlank(sId) && StringUtils.isNotBlank(sysId) && StringUtils.isNotBlank(knowId)) {
            //查询单挑打分项
            ValueData knowData = knowMapper.selectValueOnly(sysId, sId, targetId, id, knowId);
            double oldGoal = 0D;
            double value = new BigDecimal(score * weight).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue();
            if (null == knowData) {
                knowData = new ValueData();
                knowData.setId(snow.nextId() + "");
                knowData.setRelId(sysId);
                knowData.setSId(sId);
                knowData.setTargetId(targetId);
                knowData.setSubId(id);
                knowData.setKnowId(knowId);
                knowData.setScore(score);
                knowData.setWeight(weight);
                knowData.setGoal(value);
            } else {
                oldGoal = knowData.getGoal();
                knowData.setScore(score);
                knowData.setWeight(weight);
                knowData.setGoal(value);
            }
            double oldSubGoal = 0D;
            //查询子目标单条
            ValueData subData = knowMapper.selectValueOnly(sysId, sId, targetId, id, null);
            if (null == subData) {
                subData = new ValueData();
                subData.setId(snow.nextId() + "");
                subData.setRelId(sysId);
                subData.setSId(sId);
                subData.setTargetId(targetId);
                subData.setSubId(id);
                subData.setScore(value);
                subData.setWeight(0D);
                subData.setGoal(0D);
            } else {
                oldSubGoal = subData.getGoal();
                subData.setScore(new BigDecimal(subData.getScore() - oldGoal + value).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
                subData.setGoal(new BigDecimal(subData.getScore() * subData.getWeight()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
            }
            double oldTargetGoal = 0D;
            //查询目标单条
            ValueData targetData = knowMapper.selectValueOnly(sysId, sId, targetId, null, null);
            if (null == targetData) {
                targetData = new ValueData();
                targetData.setId(snow.nextId() + "");
                targetData.setRelId(sysId);
                targetData.setSId(sId);
                targetData.setTargetId(targetId);
                targetData.setScore(subData.getGoal());
                targetData.setWeight(0D);
                targetData.setGoal(0D);
            } else {
                oldTargetGoal = targetData.getGoal();
                targetData.setScore(new BigDecimal(targetData.getScore() - oldSubGoal + subData.getGoal()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
                targetData.setGoal(new BigDecimal(targetData.getScore() * targetData.getWeight()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
            }
            //查询系统单条
            ValueData systemData = knowMapper.selectValueOnly(sysId, sId, null, null, null);
            if (null == systemData) {
                systemData = new ValueData();
                systemData.setId(snow.nextId() + "");
                systemData.setRelId(sysId);
                systemData.setSId(sId);
                systemData.setScore(targetData.getGoal());
                systemData.setWeight(0D);
                systemData.setGoal(0D);
            } else {
                systemData.setScore(new BigDecimal(systemData.getScore() - oldTargetGoal + targetData.getGoal()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
                systemData.setGoal(new BigDecimal(systemData.getScore() * systemData.getWeight()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
            }
            knowMapper.addValue(systemData);
            knowMapper.addValue(targetData);
            knowMapper.addValue(subData);
            knowMapper.addValue(knowData);
        } else if (StringUtils.isNotBlank(targetId) && StringUtils.isNotBlank(sId) && StringUtils.isNotBlank(sysId)) {
            //查询子目标单条
            ValueData subData = knowMapper.selectValueOnly(sysId, sId, targetId, id, null);
            double oldGoal = 0D;
            if (null == subData) {
                subData = new ValueData();
                subData.setId(snow.nextId() + "");
                subData.setRelId(sysId);
                subData.setSId(sId);
                subData.setTargetId(targetId);
                subData.setSubId(id);
                subData.setScore(0D);
                subData.setWeight(weight);
                subData.setGoal(0D);
            } else {
                oldGoal = subData.getGoal();
                subData.setWeight(weight);
                subData.setGoal(new BigDecimal(subData.getScore() * weight).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
            }
            double targetGoal = 0D;
            //查询目标单条
            ValueData targetData = knowMapper.selectValueOnly(sysId, sId, targetId, null, null);
            if (null == targetData) {
                targetData = new ValueData();
                targetData.setId(snow.nextId() + "");
                targetData.setRelId(sysId);
                targetData.setSId(sId);
                targetData.setTargetId(targetId);
                targetData.setScore(subData.getGoal());
                targetData.setWeight(0D);
                targetData.setGoal(0D);
            } else {
                targetGoal = targetData.getGoal();
                targetData.setScore(new BigDecimal(targetData.getScore() - oldGoal + subData.getGoal()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
                targetData.setGoal(new BigDecimal(targetData.getScore() * targetData.getWeight()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
            }
            //查询系统单条
            ValueData systemData = knowMapper.selectValueOnly(sysId, sId, null, null, null);
            if (null == systemData) {
                systemData = new ValueData();
                systemData.setId(snow.nextId() + "");
                systemData.setRelId(sysId);
                systemData.setSId(sId);
                systemData.setScore(targetData.getGoal());
                systemData.setWeight(0D);
                systemData.setGoal(0D);
            } else {
                systemData.setScore(new BigDecimal(systemData.getScore() - targetGoal + targetData.getGoal()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
                systemData.setGoal(new BigDecimal(systemData.getScore() * systemData.getWeight()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
            }
            knowMapper.addValue(systemData);
            knowMapper.addValue(targetData);
            knowMapper.addValue(subData);
        } else if (StringUtils.isNotBlank(sId) && StringUtils.isNotBlank(sysId)) {
            double goal = 0D;
            //查询目标单条
            ValueData targetData = knowMapper.selectValueOnly(sysId, sId, id, null, null);
            if (null == targetData) {
                targetData = new ValueData();
                targetData.setId(snow.nextId() + "");
                targetData.setRelId(sysId);
                targetData.setSId(sId);
                targetData.setTargetId(id);
                targetData.setScore(0D);
                targetData.setWeight(weight);
                targetData.setGoal(0D);
            } else {
                goal = targetData.getGoal();
                targetData.setWeight(weight);
                targetData.setGoal(new BigDecimal(targetData.getScore() * targetData.getWeight()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
            }
            //查询系统单条
            ValueData systemData = knowMapper.selectValueOnly(sysId, sId, null, null, null);
            if (null == systemData) {
                systemData = new ValueData();
                systemData.setId(snow.nextId() + "");
                systemData.setRelId(sysId);
                systemData.setSId(sId);
                systemData.setScore(targetData.getGoal());
                systemData.setWeight(0D);
                systemData.setGoal(0D);
            } else {
                systemData.setScore(new BigDecimal(systemData.getScore() - goal + targetData.getGoal()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
                systemData.setGoal(new BigDecimal(systemData.getScore() * systemData.getWeight()).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
            }
            knowMapper.addValue(systemData);
            knowMapper.addValue(targetData);
        } else if (StringUtils.isNotBlank(sysId)) {
            //查询系统单条
            ValueData systemData = knowMapper.selectValueOnly(sysId, id, null, null, null);
            if (null == systemData) {
                systemData = new ValueData();
                systemData.setId(snow.nextId() + "");
                systemData.setRelId(sysId);
                systemData.setSId(id);
                systemData.setScore(0D);
                systemData.setWeight(weight);
                systemData.setGoal(0D);
            } else {
                systemData.setWeight(weight);
                systemData.setGoal(new BigDecimal(systemData.getScore() * weight).setScale(SUFF, BigDecimal.ROUND_HALF_DOWN).doubleValue());
            }
            knowMapper.addValue(systemData);
        } else {
            return 0;
        }
        return 1;
    }

    Result targetAnalyze(TargetData only, int type) {
        ArrayList<Map<String, Object>> infolist = new ArrayList<>();
        List<KnowData> knowDatas = new ArrayList<>();
        if (type == 0 || type == 1) {
            List<KnowData> knows = knowMapper.selectKnowTargetList(only.getType(), "结构分析");
            if (CollectionUtil.isNotEmpty(knows)) {
                knowDatas.addAll(knows);
            }
            knows = knowMapper.selectKnowTargetList(only.getType(), "功能分析");
            if (CollectionUtil.isNotEmpty(knows)) {
                knowDatas.addAll(knows);
            }
        } else {
            knowDatas = knowMapper.selectKnowTargetList(only.getType(), "特性分析");
        }
        if (CollectionUtil.isNotEmpty(knowDatas)) {
            for (KnowData knowData : knowDatas) {
                Map<String, Object> subData = new HashMap<>();
                //知识名称
                String name = "";
                //描述
                String remark = "";
                //结果
                String effect = "";
                //指标选择判断
                boolean mainJuage = false;
                //指标描述判断
                boolean mainRemarkJuage = true;
                //目标指数查询
                Map<String, Object> mainIndexMap = null;
                //指标列表
                List<String> indexList = new ArrayList<>();
                name = knowData.getName();
                remark = knowData.getRemark();
                if (StringUtils.isNotBlank(knowData.getIndexData())) {
                    mainJuage = true;
                    indexList = FileElseUtil.getStringTransitionList(knowData.getIndexData());
                }
                if (mainJuage) {
                    try {
                        if (knowData.getType().equals("1")) {
                            mainIndexMap = repo.selectTargetData(this.keyWordSystem.getFILE_URL() + only.getSqliteUrl(), indexList);
                        } else {
                            mainIndexMap = repo.selectTargetElseData(this.keyWordSystem.getFILE_URL() + only.getSqliteUrl(), indexList);
                        }
                        if (CollectionUtil.isNotEmpty(mainIndexMap) && StringUtils.isNotBlank(remark)) {
                            for (String s : mainIndexMap.keySet()) {
                                Object o = mainIndexMap.get(s);
                                if (null == o) {
                                    mainRemarkJuage = false;
                                }
                                remark = remark.replace("{" + s + "}", null != o ? o.toString() : "");
                            }
                        }
                    } catch (SQLException e) {
                        log.info("查询指标异常", e);
                    }
                }
                if (mainJuage && mainRemarkJuage && CollectionUtil.isNotEmpty(mainIndexMap)) {
                    List<KnowRelationData> effectList = knowMapper.selectKnowRelationList(knowData.getId());
                    if (CollectionUtil.isNotEmpty(effectList)) {
                        //结果判断
                        boolean effectJuage = false;
                        for (KnowRelationData relationData : effectList) {
                            for (int i = 0; i < indexList.size(); i++) {
                                double a = FileElseUtil.getStringTransitionDouble(mainIndexMap.get(indexList.get(i)).toString());
                                List indexL = FileElseUtil.getStringTransitionList(relationData.getIndexOne());
                                if (a != 0D && CollectionUtil.isNotEmpty(indexL)) {
                                    if (a >= Double.parseDouble(indexL.get(0).toString()) && a <= Double.parseDouble(indexL.get(1).toString())) {
                                        effectJuage = true;
                                    } else {
                                        effectJuage = false;
                                        break;
                                    }
                                }
                            }
                            if (effectJuage) {
                                effect = relationData.getEffect();
                                remark = remark.replace("{result}", effect);
                                break;
                            }
                        }
                    }
                }
                subData.put("name", name);
                subData.put("value", remark);
                infolist.add(subData);
            }
        }
        return ResultUtil.success(infolist);
    }

    Result subAnalyze(String sqliteUrl, String subId, int type) {
        ArrayList<Map<String, Object>> infolist = new ArrayList<>();
        try {
            Map<String, Object> subMap = repo.selectTargetSubValue(sqliteUrl, subId);
            if (CollectionUtil.isNotEmpty(subMap) && null != subMap.get("targetClassify")) {
                //前端显示封装
                List<KnowData> knowDatas = new ArrayList<>();
                if (type == 0 || type == 1) {
                    List<KnowData> knows = knowMapper.selectKnowTargetList(subMap.get("targetClassify").toString(), "结构分析");
                    if (CollectionUtil.isNotEmpty(knows)) {
                        knowDatas.addAll(knows);
                    }
                    knows = knowMapper.selectKnowTargetList(subMap.get("targetClassify").toString(), "功能分析");
                    if (CollectionUtil.isNotEmpty(knows)) {
                        knowDatas.addAll(knows);
                    }
                } else {
                    knowDatas = knowMapper.selectKnowTargetList(subMap.get("targetClassify").toString(), "特性分析");
                }
                if (CollectionUtil.isNotEmpty(knowDatas)) {
                    for (KnowData knowData : knowDatas) {
                        Map<String, Object> subData = new HashMap<>();
                        //知识名称
                        String name = "";
                        //描述
                        String remark = "";
                        //结果
                        String effect = "";
                        //指标选择判断
                        boolean mainJuage = false;
                        //指标描述判断
                        boolean mainRemarkJuage = true;
                        //目标指数查询
                        Map<String, Object> mainIndexMap = null;
                        //指标列表
                        List<String> indexList = new ArrayList<>();
                        if (null != knowData) {
                            name = knowData.getName();
                            remark = knowData.getRemark();
                            if (StringUtils.isNotBlank(knowData.getIndexData())) {
                                mainJuage = true;
                                indexList = FileElseUtil.getStringTransitionList(knowData.getIndexData());
                            }
                            if (mainJuage) {
                                try {
                                    if (knowData.getType().equals("1")) {
                                        mainIndexMap = repo.selectTargetSubValue(sqliteUrl, subId);
                                    } else {
                                        mainIndexMap = repo.selectTargetSubElseValue(sqliteUrl, subId);
                                    }
                                    if (CollectionUtil.isNotEmpty(mainIndexMap) && StringUtils.isNotBlank(remark)) {
                                        for (String s : mainIndexMap.keySet()) {
                                            Object o = mainIndexMap.get(s);
                                            if (null == o) {
                                                mainRemarkJuage = false;
                                            }
                                            remark = remark.replace("{" + s + "}", null != o ? o.toString() : "");
                                        }
                                    }
                                } catch (SQLException e) {
                                    log.info("查询指标异常", e);
                                }
                            }
                            if (mainJuage && mainRemarkJuage && CollectionUtil.isNotEmpty(mainIndexMap)) {
                                List<KnowRelationData> effectList = knowMapper.selectKnowRelationList(knowData.getId());
                                if (CollectionUtil.isNotEmpty(effectList)) {
                                    //结果判断
                                    boolean effectJuage = false;
                                    for (KnowRelationData relationData : effectList) {
                                        for (int i = 0; i < indexList.size(); i++) {
                                            if (null != mainIndexMap.get(indexList.get(i))) {
                                                double a = FileElseUtil.getStringTransitionDouble(mainIndexMap.get(indexList.get(i)).toString());
                                                List indexL = FileElseUtil.getStringTransitionList(relationData.getIndexOne());
                                                if (a != 0D && CollectionUtil.isNotEmpty(indexL)) {
                                                    if (a >= Double.parseDouble(indexL.get(0).toString()) && a <= Double.parseDouble(indexL.get(1).toString())) {
                                                        effectJuage = true;
                                                    } else {
                                                        effectJuage = false;
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                        if (effectJuage) {
                                            effect = relationData.getEffect();
                                            remark = remark.replace("{result}", effect);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        subData.put("name", name);
                        subData.put("value", remark);
                        infolist.add(subData);
                    }
                }
            }
        } catch (SQLException e) {
            log.error("子目标分析异常", e);
        }
        return ResultUtil.success(infolist);
    }

    Result systemAnalyze(SystemMaster only, int type) {
        //前端显示封装
        ArrayList<Map<String, Object>> infolist = new ArrayList<>();
        String sysType = "0";
        if (StringUtils.isNotBlank(only.getUserSign()) && only.getUserSign().split("&&").length > 1) {
            sysType = only.getUserSign().split("&&")[1];
        }
        List<KnowData> knowDatas = new ArrayList<>();
        if (type == 0 || type == 1) {
            List<KnowData> knows = knowMapper.selectKnowSystemOne(sysType, "结构分析");
            if (CollectionUtil.isNotEmpty(knows)) {
                knowDatas.addAll(knows);
            }
            knows = knowMapper.selectKnowSystemOne(sysType, "功能分析");
            if (CollectionUtil.isNotEmpty(knows)) {
                knowDatas.addAll(knows);
            }
        } else {
            knowDatas = knowMapper.selectKnowSystemOne(sysType, "特性分析");
        }
        if (CollectionUtil.isNotEmpty(knowDatas)) {
            for (KnowData knowData : knowDatas) {
                Map<String, Object> subData = new HashMap<>();
                subData.put("name", knowData.getName());
                //指标分析
                boolean mainJuage = false;
                List<String> indexList = null;
                if (StringUtils.isNotBlank(knowData.getIndexData())) {
                    mainJuage = true;
                    indexList = FileElseUtil.getStringTransitionList(knowData.getIndexData());
                }
                if (mainJuage) {
                    try {
                        Map<String, Double> value = new HashMap<>();
                        List<Map<String, Object>> list = systemRelationMapper.selectSystemRelationTargetIdAndName(only.getSId());
                        if (CollectionUtil.isNotEmpty(list)) {
                            for (Map<String, Object> map : list) {
                                TargetData targetData = targetMapper.findTargetOnly(map.get("targetId").toString());
                                if (null != targetData) {
                                    List<String> indexs = new ArrayList<>();
                                    if (CollectionUtil.isNotEmpty(indexList)) {
                                        indexs.addAll(indexList);
                                    } else {
                                        subData.put("value", knowData.getRemark());
                                        continue;
                                    }
                                    Map<String, Object> mainIndexMap = null;
                                    if (knowData.getType().equals("1")) {
                                        mainIndexMap = repo.selectTargetData(this.keyWordSystem.getFILE_URL() + targetData.getSqliteUrl(), indexs);
                                    } else {
                                        mainIndexMap = repo.selectTargetElseData(this.keyWordSystem.getFILE_URL() + targetData.getSqliteUrl(), indexs);
                                    }
                                    if (CollectionUtil.isNotEmpty(mainIndexMap) && StringUtils.isNotBlank(knowData.getRemark())) {
                                        for (String s : mainIndexMap.keySet()) {
                                            Double sum = 0.0;
                                            if (ObjectUtil.isNotEmpty(value.get(s))) {
                                                sum += FileElseUtil.getStringTransitionDouble(value.get(s).toString());
                                            } else if (ObjectUtil.isNotEmpty(mainIndexMap.get(s))) {
                                                sum += FileElseUtil.getStringTransitionDouble(mainIndexMap.get(s).toString());
                                            }
                                            value.put(s, sum);
                                        }
                                    }
                                }
                            }
                        }
                        if (CollectionUtil.isNotEmpty(value)) {
                            for (String s : value.keySet()) {
                                knowData.setRemark(knowData.getRemark().replaceAll("\\{" + s + "}", value.get(s).toString()));
                            }
                            subData.put("value", knowData.getRemark());
                        } else {
                            subData.put("value", knowData.getRemark());
                        }
                    } catch (Exception e) {
                        log.info("查询指标异常", e);
                    }
                } else {
                    subData.put("value", knowData.getRemark());
                }
                //指标分析end
                infolist.add(subData);
            }
        }
        return ResultUtil.success(infolist);
    }

    Result systemsAnalyze(SystemsMaster only, int type) {
        //前端显示封装
        ArrayList<Map<String, Object>> infolist = new ArrayList<>();
        String systemType = "0";
        if (StringUtils.isNotBlank(only.getUserSign()) && only.getUserSign().split("&&").length > 1) {
            systemType = only.getUserSign().split("&&")[1];
        }
        List<KnowData> knowDatas = new ArrayList<>();
        if (type == 0 || type == 1) {
            List<KnowData> knows = knowMapper.selectKnowSystemsOne(systemType, "结构分析");
            if (CollectionUtil.isNotEmpty(knows)) {
                knowDatas.addAll(knows);
            }
            knows = knowMapper.selectKnowSystemsOne(systemType, "功能分析");
            if (CollectionUtil.isNotEmpty(knows)) {
                knowDatas.addAll(knows);
            }
        } else {
            knowDatas = knowMapper.selectKnowSystemsOne(systemType, "特性分析");
        }
        if (CollectionUtil.isNotEmpty(knowDatas)) {
            for (KnowData knowData : knowDatas) {
                Map<String, Object> subData = new HashMap<>();
                subData.put("name", knowData.getName());
                subData.put("value", knowData.getRemark());
                infolist.add(subData);
            }
        }
        return ResultUtil.success(infolist);
    }

    /**
     * @return java.util.List<java.util.Map < java.lang.String, java.lang.Object>>
     * @author zhangxuan
     * @Description TODO 查询所有目标和子目标列表信息
     * @Date 14:49 2022/6/24
     * @Param []
     **/
    public List<Map<String, Object>> getTargetAndSubAll() {
        List<Map<String, Object>> resultList = new ArrayList<>();
        List<TargetData> all = targetMapper.findAll(null, null, null);
        if (CollectionUtil.isNotEmpty(all)) {
            Map<String, Object> map = null;
            for (TargetData target : all) {
                map = new HashMap<>();
                map.put("targetId", target.getTargetId());
                map.put("targetName", target.getTargetName());
                map.put("children", new ArrayList<>());
                resultList.add(map);
            }
        }
        return resultList;
    }

}